From: Guillermo Roditi Date: Sat, 11 Jul 2009 22:07:47 +0000 (+0000) Subject: private_path method for actions that returns a string suitable for use in forward... X-Git-Tag: 5.80008~66 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=009b5b2324f83396439a494a56684efb60eb2cd8 private_path method for actions that returns a string suitable for use in forward and unit tests for the rest of catalyst::Action --- diff --git a/Changes b/Changes index 1f7df0a..70a4777 100644 --- a/Changes +++ b/Changes @@ -9,6 +9,10 @@ Refactoring / cleanups: - Deleted the Restarter engine and its Watcher code. Use the new Catalyst::Restarter in a recent Catalyst::Devel instead. + - New unit test for Catalyst::Action 'unit_core_action.t' (groditi) + + New features: + - private_path method for Catalyst::Action + docs + tests (groditi) 5.80007 2009-06-30 23:54:34 diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index cd2d008..e9c9363 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -8,6 +8,8 @@ Catalyst::Action - Catalyst Action
+ $c->forward( $action->private_path ); + =head1 DESCRIPTION This class represents a Catalyst Action. You can access the object for the @@ -28,6 +30,13 @@ has 'reverse' => (is => 'rw'); has attributes => (is => 'rw'); has name => (is => 'rw'); has code => (is => 'rw'); +has private_path => ( + reader => 'private_path', + isa => 'Str', + lazy => 1, + required => 1, + default => sub { '/'.shift->reverse }, +); use overload ( @@ -129,6 +138,11 @@ Returns the private namespace this action lives in. Returns the private path for this action. +=head2 private_path + +Returns absolute private path for this action. Unlike C, the +C of an action is always suitable for passing to C. + =head2 name returns the sub name of this action. diff --git a/t/unit_core_action.t b/t/unit_core_action.t new file mode 100644 index 0000000..ca84422 --- /dev/null +++ b/t/unit_core_action.t @@ -0,0 +1,54 @@ +use Test::More tests => 6; +use strict; +use warnings; +use Moose::Meta::Class; +#use Moose::Meta::Attribute; +use Catalyst::Request; + +use_ok('Catalyst::Action'); + +my $action_1 = Catalyst::Action->new( + name => 'foo', + code => sub { "DUMMY" }, + reverse => 'bar/foo', + namespace => 'bar', + attributes => { + Args => [ 1 ], + attr2 => [ 2 ], + }, +); + +my $action_2 = Catalyst::Action->new( + name => 'foo', + code => sub { "DUMMY" }, + reverse => 'bar/foo', + namespace => 'bar', + attributes => { + Args => [ 2 ], + attr2 => [ 2 ], + }, +); + +is("${action_1}", $action_1->reverse, 'overload string'); +is($action_1->(), 'DUMMY', 'overload code'); + +my $anon_meta = Moose::Meta::Class->create_anon_class( + attributes => [ + Moose::Meta::Attribute->new( + request => ( + reader => 'request', + required => 1, + default => sub { Catalyst::Request->new(arguments => [qw/one two/]) }, + ), + ), + ], + methods => { req => sub { shift->request(@_) } } +); + +my $mock_c = $anon_meta->new_object(); +$mock_c->request; + +ok(!$action_1->match($mock_c), 'bad match fails'); +ok($action_2->match($mock_c), 'good match works'); + +ok($action_2->compare( $action_1 ), 'compare works');