JavaScript-Prepare
view release on metacpan or search on metacpan
bin/jsprepare view on Meta::CPAN
#!/usr/bin/env perl
use Modern::Perl;
use Getopt::Long qw( :config bundling );
use JavaScript::Prepare;
use Pod::Usage;
use POSIX qw( mkfifo );
use constant PIPE_MODE => '0444'; # mode r--r--r--
use constant OPTIONS => qw(
help|h
pipe|p=s
strip|s
);
my %option = get_options_or_exit();
my $jsprep = JavaScript::Prepare->new( strip => $option{'strip'} );
if ( $option{'pipe'} ) {
run_pipe( @ARGV );
}
print $jsprep->process( @ARGV );
exit;
sub run_pipe {
my @args = @_;
my $pipe_file = $option{'pipe'};
# clean up the pipe on exit
$SIG{'INT'} = sub {
unlink $pipe_file;
exit 0;
};
while (1) {
unless ( -p $pipe_file ) {
unlink $pipe_file;
mkfifo( $pipe_file, PIPE_MODE )
or die "Cannot make ${pipe_file}: $!";
}
open( my $pipe, '>', $pipe_file )
or die "Cannot write ${pipe_file}: $!";
print {$pipe} $jsprep->process( @args );
close $pipe;
select undef, undef, undef, 0.1;
utime undef, undef, $pipe_file;
}
}
sub get_options_or_exit {
( run in 0.539 second using v1.01-cache-2.11-cpan-140bd7fdf52 )