Catalyst-Controller-WrapCGI

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - now works on Win32

0.031  2011-05-20 23:28:23
    - fix CGIBin.pm bug hardcoding 'root' as the site root

0.030  2010-08-06 16:08:10
    - rethrow non-scalar exceptions as-is
    - minor doc fix

0.029  2010-06-05 21:12:47
    - update tests for new HTTP::Request::AsCGI

0.028  2010-04-07 17:51:38
    - added cgi_chain_root and cgi_file_pattern options for CGIBin

0.027  2010-02-19 04:34:50
    - fix tests for Perl < 5.8.9
    - fix for HTTP::Request::AsCGI 1.2

0.026  2010-01-03 11:37:15
    - convert to CGI::Compile
    - check exit status of non-Perl CGIs

0.025  2009-12-26 16:43:50
    - fix %SIG localization in CGIBin

0.024  2009-12-22 01:13:01
    - revert passing args to coderefs (some CGIs might implicitly shift off

META.json  view on Meta::CPAN

         "requires" : {
            "CGI::Compile" : "0",
            "Catalyst::Controller" : "0",
            "Catalyst::Exception" : "0",
            "Class::Unload" : "0",
            "Exporter" : "0",
            "File::Find::Rule" : "0",
            "File::Spec::Functions" : "0",
            "File::Temp" : "0",
            "File::pushd" : "0",
            "HTTP::Request" : "0",
            "HTTP::Request::AsCGI" : "0",
            "HTTP::Request::Common" : "0",
            "IO::File" : "0",
            "IPC::Open3" : "0",
            "List::MoreUtils" : "0",
            "Moose" : "0",
            "Moose::Util::TypeConstraints" : "0",
            "Scalar::Util" : "0",
            "Symbol" : "0",
            "URI" : "0",
            "URI::Escape" : "0",
            "mro" : "0",

META.yml  view on Meta::CPAN

requires:
  CGI::Compile: '0'
  Catalyst::Controller: '0'
  Catalyst::Exception: '0'
  Class::Unload: '0'
  Exporter: '0'
  File::Find::Rule: '0'
  File::Spec::Functions: '0'
  File::Temp: '0'
  File::pushd: '0'
  HTTP::Request: '0'
  HTTP::Request::AsCGI: '0'
  HTTP::Request::Common: '0'
  IO::File: '0'
  IPC::Open3: '0'
  List::MoreUtils: '0'
  Moose: '0'
  Moose::Util::TypeConstraints: '0'
  Scalar::Util: '0'
  Symbol: '0'
  URI: '0'
  URI::Escape: '0'
  mro: '0'

Makefile.PL  view on Meta::CPAN

  "PREREQ_PM" => {
    "CGI::Compile" => 0,
    "Catalyst::Controller" => 0,
    "Catalyst::Exception" => 0,
    "Class::Unload" => 0,
    "Exporter" => 0,
    "File::Find::Rule" => 0,
    "File::Spec::Functions" => 0,
    "File::Temp" => 0,
    "File::pushd" => 0,
    "HTTP::Request" => 0,
    "HTTP::Request::AsCGI" => 0,
    "HTTP::Request::Common" => 0,
    "IO::File" => 0,
    "IPC::Open3" => 0,
    "List::MoreUtils" => 0,
    "Moose" => 0,
    "Moose::Util::TypeConstraints" => 0,
    "Scalar::Util" => 0,
    "Symbol" => 0,
    "URI" => 0,
    "URI::Escape" => 0,
    "mro" => 0,

Makefile.PL  view on Meta::CPAN

  "Catalyst::Runtime" => "5.70",
  "Catalyst::Test" => 0,
  "Class::Unload" => 0,
  "Exporter" => 0,
  "File::Find::Rule" => 0,
  "File::Spec" => 0,
  "File::Spec::Functions" => 0,
  "File::Temp" => 0,
  "File::pushd" => 0,
  "FindBin" => 0,
  "HTTP::Request" => 0,
  "HTTP::Request::AsCGI" => 0,
  "HTTP::Request::Common" => 0,
  "IO::File" => 0,
  "IO::Handle" => 0,
  "IPC::Open3" => 0,
  "List::MoreUtils" => 0,
  "Moose" => 0,
  "Moose::Util::TypeConstraints" => 0,
  "Scalar::Util" => 0,
  "Symbol" => 0,
  "Test::More" => 0,
  "URI" => 0,

README  view on Meta::CPAN


    Does the magic of running $coderef in a CGI environment, and populating
    the appropriate parts of your Catalyst context with the results.

    Calls "wrap_cgi".

 wrap_cgi

    $self->wrap_cgi($c, $coderef)

    Runs $coderef in a CGI environment using HTTP::Request::AsCGI, returns
    an HTTP::Response.

    The CGI environment is set up based on $c.

    The environment variables to pass on are taken from the configuration
    for your Controller, see "SYNOPSIS" for an example. If you don't supply
    a list of environment variables to pass, the whole of %ENV is used
    (with exceptions listed in "FILTERED ENVIRONMENT".

    Used by "cgi_to_response", which is probably what you want to use as

lib/Catalyst/Controller/WrapCGI.pm  view on Meta::CPAN

package Catalyst::Controller::WrapCGI;
our $AUTHORITY = 'cpan:RKITOVER';
$Catalyst::Controller::WrapCGI::VERSION = '0.039';
use 5.008_001;
use Moose;
use mro 'c3';

extends 'Catalyst::Controller';

use Catalyst::Exception ();
use HTTP::Request::AsCGI ();
use HTTP::Request ();
use URI ();
use URI::Escape;
use HTTP::Request::Common;

use namespace::clean -except => 'meta';

=head1 NAME

Catalyst::Controller::WrapCGI - Run CGIs in Catalyst

=head1 SYNOPSIS

    package MyApp::Controller::Foo;

lib/Catalyst/Controller/WrapCGI.pm  view on Meta::CPAN

    $c->res->status($res->code);
  }
  $c->res->body($res->content);
  $c->res->headers($res->headers);
}

=head2 wrap_cgi

C<< $self->wrap_cgi($c, $coderef) >>

Runs C<$coderef> in a CGI environment using L<HTTP::Request::AsCGI>, returns an
L<HTTP::Response>.

The CGI environment is set up based on C<$c>.

The environment variables to pass on are taken from the configuration for your
Controller, see L</SYNOPSIS> for an example. If you don't supply a list of
environment variables to pass, the whole of %ENV is used (with exceptions listed
in L</FILTERED ENVIRONMENT>.

Used by L</cgi_to_response>, which is probably what you want to use as well.

=cut

sub wrap_cgi {
  my ($self, $c, $call) = @_;
  my $req = HTTP::Request->new(
    map { $c->req->$_ } qw/method uri headers/
  );
  my $body = $c->req->body;
  my $body_content = '';

  $req->content_type($c->req->content_type); # set this now so we can override

  if ($body) { # Slurp from body filehandle
    seek $body, 0, 0;
    local $/; $body_content = <$body>;

lib/Catalyst/Controller/WrapCGI.pm  view on Meta::CPAN

  my $username = (($c->can('user_exists') && $c->user_exists)
               ? eval { $c->user->obj->$username_field }
                : '');

  $username ||= $c->req->remote_user if $c->req->can('remote_user');

  my $path_info = '/'.join '/' => map {
    utf8::is_utf8($_) ? uri_escape_utf8($_) : uri_escape($_)
  } @{ $c->req->args };

  my $env = HTTP::Request::AsCGI->new(
              $req,
              ($username ? (REMOTE_USER => $username) : ()),
              PATH_INFO => $path_info,
# eww, this is likely broken:
              FILEPATH_INFO => '/'.$c->action.$path_info,
              SCRIPT_NAME => $c->uri_for($c->action, $c->req->captures)->path
            );

  {
    local *STDIN = $REAL_STDIN;   # restore the real ones so the filenos

t/cgibin.t  view on Meta::CPAN

#!perl

use strict;
use warnings;

use FindBin '$Bin';
use lib "$Bin/lib";

use Test::More;
use HTTP::Request::Common;

my %orig_sig;
BEGIN {
    %orig_sig = %SIG;
# perl < 5.8.9 won't set a %SIG entry to undef, it sets it to ''
    %orig_sig = map { defined $_ ? $_ : '' } %orig_sig
        if $] < 5.008009;
}

use Catalyst::Test 'TestCGIBin';

t/cgibin_chain_root.t  view on Meta::CPAN


use strict;
use warnings;

use FindBin '$Bin';
use lib "$Bin/lib";

use Test::More tests => 1;

use Catalyst::Test 'TestCGIBinChainRoot';
use HTTP::Request::Common;

# Test configurable path root and dir, and Chained root

my $response = request POST '/cgi/path/test.pl', [
    foo => 'bar',
    bar => 'baz',
];

is($response->content, 'foo:bar bar:baz from_chain:from_chain', 'POST to Perl CGI File');

t/cgibin_root_path.t  view on Meta::CPAN


use FindBin '$Bin';
use lib "$Bin/lib";

use Test::More tests => 3;

# Test configurable path root and dir
{ package root_test;

  use Test::More;
  use HTTP::Request::Common;
  use Catalyst::Test 'TestCGIBinRoot';

    my $response = request POST '/cgi/path/test.pl', [
        foo => 'bar',
        bar => 'baz'
       ];

    is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File');
}

# test another variation on specifying the root path
{ package another_root_test;

  use Test::More;
  use HTTP::Request::Common;
  use Catalyst::Test 'TestCGIBinRoot2';

  my $response = request POST '/cgi/path/test.pl', [
      foo => 'bar',
      bar => 'baz'
     ];

  is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File 2');
}

# test yet another variation on specifying the root path
{ package root_test_3;

  use Test::More;
  use HTTP::Request::Common;
  use Catalyst::Test 'TestCGIBinRoot3';

  my $response = request POST '/cgi/path/test.pl', [
      foo => 'bar',
      bar => 'baz'
     ];

  is($response->content, 'foo:bar bar:baz', 'POST to Perl CGI File 3');
}

t/wrap-cgi.t  view on Meta::CPAN


use strict;
use warnings;

use FindBin '$Bin';
use lib "$Bin/lib";

use Test::More tests => 9;

use Catalyst::Test 'TestApp';
use HTTP::Request::Common;

my $response = request POST '/cgi-bin/test.cgi', [
    foo => 'bar',
    bar => 'baz'
];

is($response->content, 'foo:bar bar:baz', 'POST to CGI');

$response = request POST '/cgi-bin/test.cgi', [
  foo => 'bar',



( run in 0.656 second using v1.01-cache-2.11-cpan-de7293f3b23 )