Alien-GvaScript
view release on metacpan or search on metacpan
GvaScript_Builder.pm view on Meta::CPAN
package GvaScript_Builder;
use base 'Module::Build';
use strict;
use warnings;
# some files in the distribution are derived from pod and pm sources
# so we regenerate them when doing actions "build" or "distdir"
sub ACTION_build{
my $self = shift;
$self->generate_from_sources;
$self->SUPER::ACTION_build();
}
sub ACTION_distdir{
my $self = shift;
$self->generate_from_sources;
$self->SUPER::ACTION_distdir();
}
sub ACTION_wiki {
my ($self) = @_;
$self->generate_googlewiki;
}
sub generate_from_sources {
my ($self) = @_;
$self->generate_js;
eval {$self->generate_html}; # might fail if Pod::POM is not installed
}
sub generate_js { # concatenates sources below into "GvaScript.js"
my ($self) = @_;
require "lib/Alien/GvaScript.pm";
my @sources = qw/protoExtensions event keyMap
treeNavigator choiceList autoCompleter
customButtons paginator grid
repeat form/;
my $dest = "lib/Alien/GvaScript/lib/GvaScript.js";
chmod 0777, $dest;
open my $dest_fh, ">$dest" or die "open >$dest : $!";
print $dest_fh <<__EOJS__;
/*-------------------------------------------------------------------------*
* GvaScript - Javascript framework born in Geneva.
*
* Authors: Laurent Dami <laurent.d...\@etat.ge.ch>
* Mona Remlawi
* Jean-Christophe Durand
* Sebastien Cuendet
* LICENSE
* This library is free software, you can redistribute it and/or modify
* it under the same terms as Perl's artistic license.
*
*--------------------------------------------------------------------------*/
var GvaScript = {
Version: '$Alien::GvaScript::VERSION',
REQUIRED_PROTOTYPE: '1.7',
load: function() {
function convertVersionString(versionString) {
var v = versionString.replace(/_.*|\\./g, '');
v = parseInt(v + '0'.times(4-v.length));
return versionString.indexOf('_') > -1 ? v-1 : v;
}
if((typeof Prototype=='undefined') ||
(typeof Element == 'undefined') ||
(typeof Element.Methods=='undefined') ||
(convertVersionString(Prototype.Version) <
convertVersionString(GvaScript.REQUIRED_PROTOTYPE)))
throw("GvaScript requires the Prototype JavaScript framework >= " +
GvaScript.REQUIRED_PROTOTYPE);
}
};
GvaScript.load();
__EOJS__
foreach my $sourcefile (@sources) {
open my $fh, "src/$sourcefile.js" or die $!;
print $dest_fh "\n//----------$sourcefile.js\n", <$fh>;
}
}
sub generate_html {# regenerate html doc from pod sources
my ($self) = @_;
require Pod::POM;
require Pod::POM::View::HTML;
my @podfiles = glob ("lib/Alien/GvaScript/*.pod");
my $parser = new Pod::POM;
foreach my $podfile (@podfiles) {
my $pom = $parser->parse($podfile) or die $parser->error;
$podfile =~ m[^lib/Alien/GvaScript/(.*)\.pod];
my $htmlfile = "doc/html/$1.html";
print STDERR "converting $podfile ==> $htmlfile\n";
open my $fh, ">$htmlfile" or die "open >$htmlfile: $!";
( run in 0.318 second using v1.01-cache-2.11-cpan-fa01517f264 )