[Catalyst-commits] r10163 - in
Catalyst-Plugin-RunAfterRequest/trunk:
lib/Catalyst/Model/Role t t/lib/TestApp/Controller
t/lib/TestApp/Model
evdb at dev.catalyst.perl.org
evdb at dev.catalyst.perl.org
Thu May 14 22:15:28 GMT 2009
Author: evdb
Date: 2009-05-14 22:15:27 +0000 (Thu, 14 May 2009)
New Revision: 10163
Added:
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Bar.pm
Modified:
Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm
Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t
Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm
Log:
Be careful not to override the calling modules build_per_context_instance
Modified: Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm 2009-05-14 20:13:27 UTC (rev 10162)
+++ Catalyst-Plugin-RunAfterRequest/trunk/lib/Catalyst/Model/Role/RunAfterRequest.pm 2009-05-14 22:15:27 UTC (rev 10163)
@@ -7,10 +7,21 @@
has '_context' => ( is => 'ro', weak_ref => 1 );
-sub build_per_context_instance {
- my ( $self, $c ) = @_;
+# no-op that the 'around' can wrap. Allows the higher up model to implement
+# their own 'build_per_context_instance' method.
+sub build_per_context_instance { return shift; }
+
+around build_per_context_instance => sub {
+ my $orig = shift;
+ my $self = shift;
+ my $c = shift;
+
+ warn "in C::M::R::RAR->build_per_context_instance";
+
+ $self = $self->$orig( $c, @_ );
+
bless( { %$self, _context => $c }, ref($self) );
-}
+};
sub _run_after_request {
my $self = shift;
Modified: Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t 2009-05-14 20:13:27 UTC (rev 10162)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/01basic.t 2009-05-14 22:15:27 UTC (rev 10163)
@@ -1,7 +1,7 @@
use strict;
use warnings;
use lib 't/lib';
-use Test::More tests => 4;
+use Test::More tests => 7;
use Catalyst::Test 'TestApp';
{
@@ -17,6 +17,20 @@
}
{
+ my $res = request('/foo/demonstrate_model_with_around');
+
+ ok( $res->is_success, 'Test request is a success' );
+
+ is_deeply(
+ \@TestApp::Model::Bar::data, #
+ [qw( one two TestApp )],
+ 'Data saved ok from model'
+ );
+
+ ok $TestApp::Model::Bar::BPCI_GOT_RUN, "ran local build context method";
+}
+
+{
my $res = request('/foo/demonstrate_plugin');
ok( $res->is_success, 'Test request is a success' );
Modified: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm 2009-05-14 20:13:27 UTC (rev 10162)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Controller/Foo.pm 2009-05-14 22:15:27 UTC (rev 10163)
@@ -12,6 +12,12 @@
$c->model('Foo')->demonstrate;
}
+sub demonstrate_model_with_around : Local {
+ my ( $self, $c ) = @_;
+ $c->res->body('YAY');
+ $c->model('Bar')->demonstrate;
+}
+
sub demonstrate_plugin : Local {
my ( $self, $c ) = @_;
$c->res->body('YAY');
Added: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Bar.pm
===================================================================
--- Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Bar.pm (rev 0)
+++ Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Bar.pm 2009-05-14 22:15:27 UTC (rev 10163)
@@ -0,0 +1,31 @@
+package TestApp::Model::Bar;
+
+use Moose;
+
+our @data;
+
+extends 'Catalyst::Model';
+
+with 'Catalyst::Model::Role::RunAfterRequest';
+
+our $BPCI_GOT_RUN;
+
+sub build_per_context_instance {
+ my $self=shift;
+
+ $BPCI_GOT_RUN = 1;
+
+ return $self;
+}
+
+
+sub demonstrate {
+ my $self = shift;
+ $self->_run_after_request(
+ sub { push( @data, "one" ); },
+ sub { push( @data, "two" ); },
+ sub { push @data, ref shift },
+ );
+}
+
+1;
Property changes on: Catalyst-Plugin-RunAfterRequest/trunk/t/lib/TestApp/Model/Bar.pm
___________________________________________________________________
Name: svn:keywords
+ Date Author Id Revision HeadURL
More information about the Catalyst-commits
mailing list