[Catalyst-commits] r9722 - / Catalyst-Plugin-RunAfterRequest
Catalyst-Plugin-RunAfterRequest/trunk
Catalyst-Plugin-RunAfterRequest/trunk/lib
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin
Catalyst-Plugin-RunAfterRequest/trunk/t
Catalyst-Plugin-RunAfterRequest/trunk/t/lib
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Sat Apr 18 11:55:39 GMT 2009
Author: matthewt
Date: 2009-04-18 12:55:39 +0100 (Sat, 18 Apr 2009)
New Revision: 9722
Added:
Catalyst-Plugin-RunAfterRequest/
Catalyst-Plugin-RunAfterRequest/trunk/
Catalyst-Plugin-RunAfterRequest/trunk/Makefile.PL
Catalyst-Plugin-RunAfterRequest/trunk/lib/
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin/
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin/RunAfterRequest.pm
Catalyst-Plugin-RunAfterRequest/trunk/t/
Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp.pm
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Foo.pm
Log:
run after request plugin
Added: Catalyst-Plugin-RunAfterRequest/trunk/Makefile.PL
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/Makefile.PL (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/Makefile.PL 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use inc::Module::Install;
+
+name('Catalyst-Plugin-RunAfterRequest');
+
+all_from('lib/Catalyst/Plugin/RunAfterRequest.pm');
+
+requires 'Catalyst::Runtime';
+requires 'Catalyst::Component::InstancePerContext';
+requires 'Moose';
+
+WriteAll;
Added: Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,20 @@
+package Catalyst::Model::Role::RunAfterRequest;
+
+use Moose::Role;
+use Catalyst::Component::InstancePerContext;
+
+with 'Catalyst::Component::InstancePerContext';
+
+has '_context' => (is => 'ro', weak_ref => 1);
+
+sub build_per_context_instance {
+ my ($self, $c) = @_;
+ bless({ %$self, _context => $c}, ref($self));
+}
+
+sub _run_after_request {
+ my $self = shift;
+ $self->_context->run_after_request(@_);
+}
+
+1;
Added: Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin/RunAfterRequest.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin/RunAfterRequest.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Plugin/RunAfterRequest.pm 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,37 @@
+package Catalyst::Plugin::RunAfterRequest;
+
+use strict;
+use warnings;
+use MRO::Compat;
+
+our $VERSION = '1.000000';
+
+sub run_after_request {
+ my $self = shift;
+ push(@{$self->{run_after_request}||=[]}, @_);
+}
+
+sub finalize {
+ my $self = shift;
+ $self->next::method(@_);
+ $self->_run_code_after_request;
+}
+
+sub _run_code_after_request {
+ my $self = shift;
+ $_->($self) for @{$self->{run_after_request}||[]};
+}
+
+=head1 NAME
+
+Catalyst::Plugin::RunAfterRequest - run things after the response has been sent
+
+=head1 AUTHOR
+
+Matt S Trout (mst) <mst at shadowcat.co.uk>
+
+Edmund Von Der Burg (evdb) <email here>
+
+=cut
+
+1;
Added: Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More qw(no_plan);
+use Catalyst::Test 'TestApp';
+
+my $res = request('/foo/demonstrate');
+
+ok($res->is_success, 'Test request is a success');
+
+is_deeply(
+ \@TestApp::Model::Foo::data,
+ [ qw(one two) ],
+ 'Data saved ok'
+);
Added: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,12 @@
+package TestApp::Controller::Foo;
+
+use base qw(Catalyst::Controller);
+use Moose;
+
+sub demonstrate :Local {
+ my ($self, $c) = @_;
+ $c->res->body('YAY');
+ $c->model('Foo')->demonstrate;
+}
+
+1;
Added: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Foo.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Foo.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Foo.pm 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,19 @@
+package TestApp::Model::Foo;
+
+use Moose;
+
+our @data;
+
+extends 'Catalyst::Model';
+
+with 'Catalyst::Model::Role::RunAfterRequest';
+
+sub demonstrate {
+ my $self = shift;
+ $self->_run_after_request(
+ sub { push(@data, "one"); },
+ sub { push(@data, "two"); },
+ );
+}
+
+1;
Added: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp.pm 2009-04-18 11:55:39 UTC (rev 9722)
@@ -0,0 +1,8 @@
+package TestApp;
+
+use base qw(Catalyst);
+use Catalyst qw(RunAfterRequest);
+
+__PACKAGE__->setup;
+
+1;
More information about the Catalyst-commits
mailing list