| 1 | #!/usr/bin/env perl |
|---|
| 2 | # |
|---|
| 3 | # $Id: Build.PL 4 2006-12-26 01:39:04Z hironori.yoshida $ |
|---|
| 4 | # |
|---|
| 5 | package main; |
|---|
| 6 | use strict; |
|---|
| 7 | use warnings; |
|---|
| 8 | use utf8; |
|---|
| 9 | our $VERSION = eval { require version; version::qv('0.03') }; |
|---|
| 10 | |
|---|
| 11 | use Carp; |
|---|
| 12 | use English qw(-no_match_vars); |
|---|
| 13 | use Module::Build::JSAN; |
|---|
| 14 | |
|---|
| 15 | my $build = Module::Build::JSAN->new( |
|---|
| 16 | module_name => 'JSONScriptRequest', |
|---|
| 17 | license => 'mit', |
|---|
| 18 | dist_author => 'Hironori Yoshida <yoshida@cpan.org>', |
|---|
| 19 | dist_abstract => 'Call the JSONP API like XMLHttpRequest', |
|---|
| 20 | dist_version => $VERSION, |
|---|
| 21 | keywords => [qw(json script request ajax XMLHttpRequest)], |
|---|
| 22 | build_requires => { 'Test.Simple' => 0.21, }, |
|---|
| 23 | requires => {}, |
|---|
| 24 | sign => 1, |
|---|
| 25 | ); |
|---|
| 26 | $build->create_build_script; |
|---|
| 27 | |
|---|
| 28 | open my $fh, '>>', 'Build' or croak $OS_ERROR; |
|---|
| 29 | print {$fh} <<'EOF'; |
|---|
| 30 | |
|---|
| 31 | BEGIN { |
|---|
| 32 | $ENV{PERL5LIB} ||= q{}; # avoid warnings at Module/Build/Base.pm:4000 |
|---|
| 33 | if ( my $_strip_pod = Module::Build::JSAN->can('_strip_pod') ) { |
|---|
| 34 | undef *Module::Build::JSAN::_strip_pod; ## no critic |
|---|
| 35 | *Module::Build::JSAN::_strip_pod = sub { ## no critic |
|---|
| 36 | my ( $self, $dist_dir ) = @_; |
|---|
| 37 | |
|---|
| 38 | my $files = $self->find_js_files; |
|---|
| 39 | foreach my $file ( keys %{$files} ) { |
|---|
| 40 | $files->{$file} = ( stat "$dist_dir/$file" )[2]; |
|---|
| 41 | chmod oct(644), "$dist_dir/$file"; |
|---|
| 42 | } |
|---|
| 43 | $_strip_pod->(@_); |
|---|
| 44 | foreach my $file ( keys %{$files} ) { |
|---|
| 45 | chmod $files->{$file}, "$dist_dir/$file"; |
|---|
| 46 | } |
|---|
| 47 | }; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | { |
|---|
| 52 | |
|---|
| 53 | package Module::Build::JSAN; |
|---|
| 54 | |
|---|
| 55 | use Carp; |
|---|
| 56 | use English qw(-no_match_vars); |
|---|
| 57 | use File::Path; |
|---|
| 58 | |
|---|
| 59 | sub ACTION_build { ## no critic (NamingConventions::ProhibitMixedCaseSubs) |
|---|
| 60 | eval { |
|---|
| 61 | require JavaScript::Squish; |
|---|
| 62 | my $self = shift; |
|---|
| 63 | |
|---|
| 64 | my $infile = 'lib/' . $self->module_name . '.js'; |
|---|
| 65 | open my $fh, '<', $infile or croak $OS_ERROR; |
|---|
| 66 | my $js = do { local $INPUT_RECORD_SEPARATOR = undef; <$fh> }; |
|---|
| 67 | close $fh; |
|---|
| 68 | my $compacted = JavaScript::Squish->squish($js) or croak; |
|---|
| 69 | ( my $copyright = $js ) =~ s{.*\s*(Copyright[^\n]*\n).*}{// $1}msx; |
|---|
| 70 | $compacted = $copyright . $compacted; |
|---|
| 71 | |
|---|
| 72 | my $outfile = $self->blib . q{/} . $infile; |
|---|
| 73 | mkpath( [ $self->blib . '/lib' ], 1, oct 755 ); |
|---|
| 74 | print {*STDERR} "js_compactor $infile => $outfile\n"; |
|---|
| 75 | open $fh, '>', $outfile or croak $OS_ERROR; |
|---|
| 76 | print {$fh} $compacted; |
|---|
| 77 | close $fh; |
|---|
| 78 | }; |
|---|
| 79 | if ($EVAL_ERROR) { |
|---|
| 80 | print {*STDOUT} $EVAL_ERROR; |
|---|
| 81 | } |
|---|
| 82 | return; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | EOF |
|---|