1 package Catalyst::Plugin::CGIBin;
8 use File::Slurp 'slurp';
9 use File::Find::Rule ();
11 use Catalyst::Exception ();
15 Catalyst::Plugin::CGIBin - Serve CGIs from root/cgi-bin
23 our $VERSION = '0.001';
31 __PACKAGE__->setup(qw/CGIBin/);
48 Dispatches to executable CGI files in root/cgi-bin through the configured
49 controller, which must inherit from L<Catalyst::Controller::WrapCGI>.
53 my ($cgi_controller, $cgis);
60 my $cgi_bin = $app->path_to('root', 'cgi-bin');
63 Catalyst::Exception->throw(
64 message => 'You have no root/cgi-bin directory'
67 $cgi_controller = $app->config->{'Plugin::CGIBin'}{controller} ||
68 Catalyst::Exception->throw(
69 message => 'You must configure a controller for Plugin::CGIBin'
72 for my $cgi (File::Find::Rule->executable->file->in(".")) {
73 my $code = do { no warnings; eval 'sub { '.slurp($cgi).' }' };
74 if (!$@) { # Perl source
75 $cgis->{$cgi} = $code;
77 } else { # some other type of executable
78 $cgis->{$cgi} = sub { system "$cgi_bin/$cgi" };
84 $app->next::method(@_);
89 my $path = uri_unescape($c->req->path);
91 if ($path =~ m!^cgi-bin/(.*)!) {
92 my $cgi = $cgis->{$1};
95 $c->controller($cgi_controller)->cgi_to_response(
102 $c->next::method(@_);
107 Rafael Kitover, C<< <rkitover at cpan.org> >>
111 Please report any bugs or feature requests to C<bug-catalyst-controller-wrapcgi at
112 rt.cpan.org>, or through the web interface at
113 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Controller-WrapCGI>.
114 I will be notified, and then you'll automatically be notified of progress on
115 your bug as I make changes.
123 =item * RT: CPAN's request tracker
125 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Controller-WrapCGI>
127 =item * AnnoCPAN: Annotated CPAN documentation
129 L<http://annocpan.org/dist/Catalyst-Controller-WrapCGI>
133 L<http://cpanratings.perl.org/d/Catalyst-Controller-WrapCGI>
137 L<http://search.cpan.org/dist/Catalyst-Controller-WrapCGI>
141 =head1 COPYRIGHT & LICENSE
143 Copyright (c) 2008 Rafael Kitover
145 This program is free software; you can redistribute it and/or modify it
146 under the same terms as Perl itself.
150 1; # End of Catalyst::Plugin::CGIBin
152 # vim: expandtab shiftwidth=4 ts=4 tw=80: