use strict;
use warnings;
-use Class::C3;
+use MRO::Compat;
+use mro 'c3';
use File::Slurp 'slurp';
use File::Find::Rule ();
use Catalyst::Exception ();
use Symbol 'gensym';
use List::MoreUtils 'any';
use IO::File ();
+use Carp;
use namespace::clean -except => 'meta';
use parent 'Catalyst::Controller::WrapCGI';
=head1 VERSION
-Version 0.004
+Version 0.006
=cut
-our $VERSION = '0.004';
+our $VERSION = '0.006';
=head1 SYNOPSIS
my $path = join '/' => splitdir($cgi_path);
my $action_name = $self->cgi_action($path);
+ my $public_path = $self->cgi_path($path);
my $reverse = $namespace ? "$namespace/$action_name" : $action_name;
- my $attrs = { Path => [ "cgi-bin/$path" ], Args => [ 0 ] };
+ my $attrs = { Path => [ $public_path ], Args => [ 0 ] };
my ($cgi, $type);
=head1 METHODS
-=head2 $self->cgi_action($cgi_path)
+=head2 $self->cgi_action($cgi)
Takes a path to a CGI from C<root/cgi-bin> such as C<foo/bar.cgi> and returns
the action name it is registered as. See L</DESCRIPTION> for a discussion on how
$action_name
}
+=head2 $self->cgi_path($cgi)
+
+Takes a path to a CGI from C<root/cgi-bin> such as C<foo/bar.cgi> and returns
+the public path it should be registered under.
+
+The default is C<cgi-bin/$cgi>.
+
+=cut
+
+sub cgi_path {
+ my ($self, $cgi) = @_;
+ return "cgi-bin/$cgi";
+}
+
=head2 $self->is_perl_cgi($path)
Tries to figure out whether the CGI is Perl or not.
sub wrap_perl_cgi {
my ($self, $cgi, $action_name) = @_;
- do {
+ my $code = slurp $cgi;
+
+ $code =~ s/^__DATA__\r?\n(.*)//ms;
+ my $data = $1;
+
+ my $coderef = do {
no warnings;
-# CGIs import stuff, so putting them into this package breaks Cat 5.8
eval '
package Catalyst::Controller::CGIBin::_CGIs_::'.$action_name.';
- sub {' . slurp($cgi) . '}'
- }
+ sub {'
+ . 'local *DATA;'
+ . q{open DATA, '<', \$data;}
+ . $code
+ . '}';
+ };
+
+ croak __PACKAGE__ . ": Could not compile $cgi to coderef: $@" if $@;
+
+ $coderef
}
=head2 $self->wrap_nonperl_cgi($path, $action_name)