diff -Nru libcgi-compile-perl-0.23/Changes libcgi-compile-perl-0.24/Changes --- libcgi-compile-perl-0.23/Changes 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/Changes 2020-01-30 14:00:00.000000000 +0000 @@ -1,5 +1,10 @@ Revision history for Perl extension CGI::Compile +0.24 2020-01-30 13:59:56 UTC + - use better packages/subnames for coderefs + - add all CONTRIBUTORS to POD + - add test for working alarm signal in CGIs + 0.23 2020-01-17 10:31:33 UTC - fix race condition in temp dir creation (jr-dimedis) #24 diff -Nru libcgi-compile-perl-0.23/cpanfile libcgi-compile-perl-0.24/cpanfile --- libcgi-compile-perl-0.23/cpanfile 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/cpanfile 2020-01-30 14:00:00.000000000 +0000 @@ -1,5 +1,6 @@ requires 'perl', '5.008001'; requires 'File::pushd'; +requires 'Sub::Name'; on configure => sub { requires 'Module::Build::Tiny'; @@ -13,6 +14,7 @@ requires 'Try::Tiny'; requires 'CGI'; requires 'Switch'; + requires 'Sub::Identify'; }; on develop => sub { diff -Nru libcgi-compile-perl-0.23/debian/changelog libcgi-compile-perl-0.24/debian/changelog --- libcgi-compile-perl-0.23/debian/changelog 2020-01-24 13:40:40.000000000 +0000 +++ libcgi-compile-perl-0.24/debian/changelog 2020-02-03 13:32:20.000000000 +0000 @@ -1,3 +1,10 @@ +libcgi-compile-perl (0.24-1) unstable; urgency=medium + + * Import upstream version 0.24. + * Update (build) dependencies. + + -- gregor herrmann Mon, 03 Feb 2020 14:32:20 +0100 + libcgi-compile-perl (0.23-1) unstable; urgency=medium [ Xavier Guimard ] diff -Nru libcgi-compile-perl-0.23/debian/control libcgi-compile-perl-0.24/debian/control --- libcgi-compile-perl-0.23/debian/control 2020-01-24 13:40:40.000000000 +0000 +++ libcgi-compile-perl-0.24/debian/control 2020-02-03 13:32:20.000000000 +0000 @@ -11,6 +11,8 @@ Build-Depends-Indep: libcapture-tiny-perl , libcgi-pm-perl , libfile-pushd-perl , + libsub-identify-perl , + libsub-name-perl , libswitch-perl , libtest-nowarnings-perl , libtest-requires-perl , @@ -27,7 +29,8 @@ Architecture: all Depends: ${misc:Depends}, ${perl:Depends}, - libfile-pushd-perl + libfile-pushd-perl, + libsub-name-perl Recommends: libcgi-emulate-psgi-perl Description: module for compiling .cgi scripts to a code reference CGI::Compile is an utility to compile CGI scripts into a code reference that diff -Nru libcgi-compile-perl-0.23/lib/CGI/Compile.pm libcgi-compile-perl-0.24/lib/CGI/Compile.pm --- libcgi-compile-perl-0.23/lib/CGI/Compile.pm 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/lib/CGI/Compile.pm 2020-01-30 14:00:00.000000000 +0000 @@ -3,7 +3,7 @@ use strict; use 5.008_001; -our $VERSION = '0.23'; +our $VERSION = '0.24'; use Cwd; use File::Basename; @@ -12,6 +12,7 @@ use File::Temp; use File::Spec; use File::Path; +use Sub::Name 'subname'; our $RETURN_EXIT_VAL = undef; @@ -53,21 +54,33 @@ die $@ if $@; } +my %anon; + sub compile { my($class, $script, $package) = @_; my $self = ref $class ? $class : $class->new; - my($code, $path, $dir); + my($code, $path, $dir, $subname); + if (ref $script eq 'SCALAR') { - $code = $$script; + $code = $$script; + + $package ||= (caller)[0]; + + $subname = '__CGI' . $anon{$package}++ . '__'; } else { $code = $self->_read_source($script); + $path = Cwd::abs_path($script); $dir = File::Basename::dirname($path); - } - $package ||= $self->_build_package($path || $script); + my $genned_package; + + ($genned_package, $subname) = $self->_build_subname($path || $script); + + $package ||= $genned_package; + } my $warnings = $code =~ /^#!.*\s-w\b/ ? 1 : 0; $code =~ s/^__END__\r?\n.*//ms; @@ -77,7 +90,7 @@ # TODO handle nph and command line switches? my $eval = join '', "package $package;", - "sub {", + 'sub {', 'local $CGI::Compile::USE_REAL_EXIT = 0;', "\nCGI::initialize_globals() if defined &CGI::initialize_globals;", 'local ($0, $CGI::Compile::_dir, *DATA);', @@ -119,7 +132,6 @@ }, '};'; - my $sub = do { no warnings 'uninitialized'; # for 5.8 # NOTE: this is a workaround to fix a problem in Perl 5.10 @@ -131,7 +143,7 @@ die "Could not compile $script: $exception" if $exception; - sub { + subname "${package}::$subname", sub { my @args = @_; # this is necessary for MSWin32 my $orig_warn = $SIG{__WARN__} || sub { warn(@_) }; @@ -150,21 +162,24 @@ return do { local $/; <$fh> }; } -sub _build_package { +sub _build_subname { my($self, $path) = @_; my ($volume, $dirs, $file) = File::Spec::Functions::splitpath($path); my @dirs = File::Spec::Functions::splitdir($dirs); - my $package = join '_', grep { defined && length } $volume, @dirs, $file; + + my $package = join '_', grep { defined && length } $volume, @dirs; + my $name = $file; # Escape everything into valid perl identifiers - $package =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg; + s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg for $package, $name; - # make sure that the sub-package doesn't start with a digit - $package =~ s/^(\d)/_$1/; + # make sure the identifiers don't start with a digit + s/^(\d)/_$1/ for $package, $name; - $package = $self->{namespace_root} . "::$package"; - return $package; + $package = $self->{namespace_root} . ($package ? "::$package" : ''); + + return ($package, $name); } # define tmp_dir value later on first usage, otherwise all children @@ -446,10 +461,11 @@ =back -=head2 _build_package +=head2 _build_subname -Creates a package name into which the CGI coderef will be compiled into, -prepended with C<$self->{namespace_root}>. +Creates a package name and coderef name into which the CGI coderef will be +compiled into. The package name will be prepended with +C<$self->{namespace_root}>. Parameters: @@ -472,6 +488,15 @@ =back +=over 4 + +=item * C<$subname> + +The generated coderef name, based on the file name (without directory) of the +CGI file path. + +=back + =head2 _eval Takes the generated perl code, which is the contents of the CGI script @@ -508,7 +533,7 @@ =head1 CONTRIBUTORS -Rafael Kitover Erkitover@cpan.orgE +Rafael Kitover Erkitover@gmail.comE Hans Dieter Pearcey Ehdp@cpan.orgE @@ -516,6 +541,12 @@ Torsten Förtsch Etorsten.foertsch@gmx.netE +Jörn Reder Ejreder@dimedis.deE + +Pavel Mateja Epavel@verotel.czE + +lestrrat Elestrrat+github@gmail.comE + =head1 COPYRIGHT & LICENSE Copyright (c) 2020 Tatsuhiko Miyagawa Emiyagawa@bulknews.netE diff -Nru libcgi-compile-perl-0.23/MANIFEST libcgi-compile-perl-0.24/MANIFEST --- libcgi-compile-perl-0.23/MANIFEST 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/MANIFEST 2020-01-30 14:00:00.000000000 +0000 @@ -11,6 +11,7 @@ lib/CGI/Compile.pm t/00_compile.t t/Exit.pm +t/alarm.t t/args.cgi t/author-pod-syntax.t t/chained_exit.t @@ -35,5 +36,6 @@ t/source.t t/source_filter.t t/switch.cgi +t/symbols.t t/warnings.cgi t/warnings.t diff -Nru libcgi-compile-perl-0.23/META.json libcgi-compile-perl-0.24/META.json --- libcgi-compile-perl-0.23/META.json 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/META.json 2020-01-30 14:00:00.000000000 +0000 @@ -45,6 +45,7 @@ "runtime" : { "requires" : { "File::pushd" : "0", + "Sub::Name" : "0", "perl" : "5.008001" } }, @@ -52,6 +53,7 @@ "requires" : { "CGI" : "0", "Capture::Tiny" : "0", + "Sub::Identify" : "0", "Switch" : "0", "Test::More" : "0", "Test::NoWarnings" : "0", @@ -72,7 +74,7 @@ "web" : "https://github.com/miyagawa/CGI-Compile" } }, - "version" : "0.23", + "version" : "0.24", "x_contributors" : [ "Hans Dieter Pearcey ", "J\u00f6rn Reder ", diff -Nru libcgi-compile-perl-0.23/META.yml libcgi-compile-perl-0.24/META.yml --- libcgi-compile-perl-0.23/META.yml 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/META.yml 2020-01-30 14:00:00.000000000 +0000 @@ -5,6 +5,7 @@ build_requires: CGI: '0' Capture::Tiny: '0' + Sub::Identify: '0' Switch: '0' Test::More: '0' Test::NoWarnings: '0' @@ -29,12 +30,13 @@ - xt requires: File::pushd: '0' + Sub::Name: '0' perl: '5.008001' resources: bugtracker: https://github.com/miyagawa/CGI-Compile/issues homepage: https://github.com/miyagawa/CGI-Compile repository: https://github.com/miyagawa/CGI-Compile.git -version: '0.23' +version: '0.24' x_contributors: - 'Hans Dieter Pearcey ' - 'Jörn Reder ' diff -Nru libcgi-compile-perl-0.23/README libcgi-compile-perl-0.24/README --- libcgi-compile-perl-0.23/README 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/README 2020-01-30 14:00:00.000000000 +0000 @@ -220,10 +220,11 @@ The contents of the file as a scalar string. - _build_package + _build_subname - Creates a package name into which the CGI coderef will be compiled - into, prepended with $self-{namespace_root}>. + Creates a package name and coderef name into which the CGI coderef will + be compiled into. The package name will be prepended with + $self-{namespace_root}>. Parameters: @@ -238,6 +239,11 @@ The generated package name. + * $subname + + The generated coderef name, based on the file name (without + directory) of the CGI file path. + _eval Takes the generated perl code, which is the contents of the CGI script @@ -267,7 +273,7 @@ CONTRIBUTORS - Rafael Kitover + Rafael Kitover Hans Dieter Pearcey @@ -275,6 +281,12 @@ Torsten Förtsch + Jörn Reder + + Pavel Mateja + + lestrrat + COPYRIGHT & LICENSE Copyright (c) 2020 Tatsuhiko Miyagawa diff -Nru libcgi-compile-perl-0.23/t/alarm.t libcgi-compile-perl-0.24/t/alarm.t --- libcgi-compile-perl-0.23/t/alarm.t 1970-01-01 00:00:00.000000000 +0000 +++ libcgi-compile-perl-0.24/t/alarm.t 2020-01-30 14:00:00.000000000 +0000 @@ -0,0 +1,34 @@ +#!/usr/bin/env perl; +use strict; +use warnings; + +use Test::More $^O eq 'MSWin32' ? ( + skip_all => 'not supported on Win32') +: ( + tests => 1 +); + +use CGI::Compile; +use Capture::Tiny 'capture_stdout'; + +my $cgi =<<'EOL'; +#!/usr/bin/perl + +use strict; +use warnings; +use Time::HiRes 'ualarm'; + +print "Content-Type: text/plain\015\012\015\012"; + +$SIG{ALRM} = sub { print "ALARM\015\012" }; + +ualarm 50; +sleep 1; +EOL + +my $sub = CGI::Compile->compile(\$cgi); + +like capture_stdout { $sub->() }, + qr/ALARM/; + +done_testing; diff -Nru libcgi-compile-perl-0.23/t/source.t libcgi-compile-perl-0.24/t/source.t --- libcgi-compile-perl-0.23/t/source.t 2020-01-17 10:31:36.000000000 +0000 +++ libcgi-compile-perl-0.24/t/source.t 2020-01-30 14:00:00.000000000 +0000 @@ -1,9 +1,12 @@ +#!/usr/bin/env perl + +use strict; +use warnings; use Test::More; use CGI::Compile; use Capture::Tiny 'capture_stdout'; -{ - my $str =<; @@ -13,10 +16,11 @@ World EOL - my $sub = CGI::Compile->compile(\$str); - my $out = capture_stdout { $sub->() }; - like $out, qr/Hello\nWorld/; -} +my $sub = CGI::Compile->compile(\$cgi); + +my $out = capture_stdout { $sub->() }; + +like $out, qr/Hello\nWorld/; done_testing; diff -Nru libcgi-compile-perl-0.23/t/symbols.t libcgi-compile-perl-0.24/t/symbols.t --- libcgi-compile-perl-0.23/t/symbols.t 1970-01-01 00:00:00.000000000 +0000 +++ libcgi-compile-perl-0.24/t/symbols.t 2020-01-30 14:00:00.000000000 +0000 @@ -0,0 +1,43 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use CGI::Compile; +use Capture::Tiny 'capture_stdout'; +use Test::Requires 'Sub::Identify'; + +use Sub::Identify qw/sub_name stash_name/; + +my $cgi =<<'EOL'; +#!/usr/bin/perl + +print "Content-Type: text/plain\015\012\015\012", ; + +__DATA__ +Hello +World +EOL + +my $sub = CGI::Compile->compile(\$cgi); + +is sub_name($sub), '__CGI0__'; +is stash_name($sub), 'main'; + +$sub = CGI::Compile->compile('t/hello.cgi'); + +is sub_name($sub), 'hello_2ecgi'; + +like stash_name($sub), qr/^CGI::Compile::ROOT::[A-Za-z0-9_]*t\z/; + +$sub = CGI::Compile->compile(\$cgi); + +is sub_name($sub), '__CGI1__'; +is stash_name($sub), 'main'; + +my $out = capture_stdout { $sub->() }; + +like $out, qr/Hello\nWorld/; + +done_testing; +