Added: Initial import of C-P-SubReq
Marcus Ramberg [Mon, 18 Apr 2005 19:51:33 +0000 (19:51 +0000)]
Changes [new file with mode: 0644]
MANIFEST [new file with mode: 0644]
META.yml [new file with mode: 0644]
Makefile.PL [new file with mode: 0644]
README [new file with mode: 0644]
SubRequest.pm [new file with mode: 0644]
t/01use.t [new file with mode: 0644]
t/02subreq.t [new file with mode: 0644]
t/lib/TestApp.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
new file mode 100644 (file)
index 0000000..d82b5cb
--- /dev/null
+++ b/Changes
@@ -0,0 +1,11 @@
+Revision history for Perl extension Catalyst::Plugin::Static.
+
+0.04  Sat Mar 19 20:27:00 2005
+        - Updated forward to cat5 style
+0.03  Sat Mar 19 20:27:00 2005
+        - Fixed documentation.
+0.02  Sat Feb 19 10:32:00 2005
+        - Ooops, missed MANIFEST
+
+0.01  Fri Mar 5 22:00:00 2005
+        - first release
diff --git a/MANIFEST b/MANIFEST
new file mode 100644 (file)
index 0000000..0b0af9d
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,9 @@
+Changes
+Makefile.PL
+MANIFEST                       This list of files
+META.yml
+README
+SubRequest.pm
+t/01use.t
+t/02subreq.t
+t/lib/TestApp.pm
diff --git a/META.yml b/META.yml
new file mode 100644 (file)
index 0000000..b1d8f6b
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Catalyst-Plugin-SubRequest
+version:      0.04
+version_from: SubRequest.pm
+installdirs:  site
+requires:
+    Catalyst:                      2.99
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644 (file)
index 0000000..25fbb25
--- /dev/null
@@ -0,0 +1,10 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME      => 'Catalyst::Plugin::SubRequest',
+    AUTHOR    => 'Marcus Ramberg <marcus@thefeed.no>',
+    PREREQ_PM => {
+        Catalyst     => '2.99',
+    },
+    VERSION_FROM => 'SubRequest.pm'
+);
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..c41fd35
--- /dev/null
+++ b/README
@@ -0,0 +1,23 @@
+NAME
+    Catalyst::Plugin::Static - Serve static files with Catalyst
+
+SYNOPSIS
+        use Catalyst 'Static';
+
+        $c->serve_static;
+
+DESCRIPTION
+    Serve static files from config->{root}.
+
+  METHODS
+   serve_static
+SEE ALSO
+    Catalyst.
+
+AUTHOR
+    Sebastian Riedel, "sri@cpan.org"
+
+COPYRIGHT
+    This program is free software, you can redistribute it and/or modify it
+    under the same terms as Perl itself.
+
diff --git a/SubRequest.pm b/SubRequest.pm
new file mode 100644 (file)
index 0000000..d8f5b20
--- /dev/null
@@ -0,0 +1,74 @@
+package Catalyst::Plugin::SubRequest;
+
+use strict;
+
+our $VERSION = '0.04';
+
+
+=head1 NAME
+
+Catalyst::Plugin::SubRequest - Make subrequests to actions in Catalyst
+
+=head1 SYNOPSIS
+
+    use Catalyst 'SubRequest';
+
+    $c->subreq('!test','foo','bar');
+
+=head1 DESCRIPTION
+
+Make subrequests to actions in Catalyst.
+
+=head1 METHODS
+
+=over 4 
+
+=item subreq action, args
+
+=item sub_request
+
+takes the name of the action you would like to call, as well as the
+arguments you want to pass to it.
+
+=back 
+
+=cut
+
+*subreq = \&sub_request;
+
+sub sub_request {
+    my ( $c, $action, @args ) = @_;
+    my %old_req;
+    $old_req{stash}   = $c->{stash};$c->{stash}={};
+    $old_req{content} = $c->res->output;$c->res->output(undef);
+    $old_req{args}    = $c->req->arguments;$c->req->arguments([@args]);
+    $old_req{action}  = $c->req->action;$c->req->action($action);
+    $c->dispatch();
+    my $output  = $c->res->output;
+    $c->{stash} = $old_req{stash};
+    $c->res->output($old_req{content});
+    $c->req->arguments($old_req{args});
+    $c->req->action($old_req{action});
+    return $output;
+}
+
+=head1 SEE ALSO
+
+L<Catalyst>.
+
+=head1 AUTHOR
+
+Marcus Ramberg, C<mramberg@cpan.org>
+
+=head1 THANK YOU
+
+SRI, for writing the awesome Catalyst framework
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/t/01use.t b/t/01use.t
new file mode 100644 (file)
index 0000000..0913c19
--- /dev/null
+++ b/t/01use.t
@@ -0,0 +1,4 @@
+use strict;
+use Test::More tests => 1;
+
+BEGIN { use_ok('Catalyst::Plugin::SubRequest') }
diff --git a/t/02subreq.t b/t/02subreq.t
new file mode 100644 (file)
index 0000000..238e283
--- /dev/null
@@ -0,0 +1,23 @@
+package main;
+
+use Test::More tests => 6;
+use lib 't/lib';
+use Catalyst::Test 'TestApp';
+use File::stat;
+use File::Slurp;
+use HTTP::Date;
+
+my $stat = stat($0);
+
+{
+    ok( my $response = request('/normal'),    'Normal Request'  );
+    is( $response->code, 200,                 'OK status code'  );
+    is( $response->content, '123',    'Normal request content', );
+}
+
+{
+    ok( my $response = request('/subreq'),    'Sub Request'     );
+    is( $response->code, 200,                 'OK status code'  );
+    is( $response->content, '11233',    'Normal request content', );
+}
+
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
new file mode 100644 (file)
index 0000000..19d0c33
--- /dev/null
@@ -0,0 +1,36 @@
+package TestApp;
+
+use Catalyst qw[-Engine=Test SubRequest];
+
+__PACKAGE__->config(
+    name=>"subrequest test"
+);
+
+__PACKAGE__->setup();
+
+    sub begin : Private {
+        my ( $self, $c ) = @_;
+        $c->res->body($c->res->body().'1');
+    }
+
+    sub subreq : Global {
+        my ( $self, $c ) = @_;
+        $c->log->info("self is ".  ref $self);
+        $c->log->info("Context is ". ref $c);
+        my $subreq= $c->res->body() .
+                        $c->subreq('/normal');
+        $c->res->body($subreq);
+    }
+  
+    sub normal : Global {
+        my ( $self, $c ) = @_;
+        $c->res->body($c->res->body().'2');
+    }
+    
+    sub end : Private {
+        my ( $self, $c ) = @_;
+        $c->res->body($c->res->body().'3');
+    }
+
+
+1;