[Catalyst-commits] r10861 - in Catalyst-Runtime/5.80/trunk: .
lib/Catalyst t
groditi at dev.catalyst.perl.org
groditi at dev.catalyst.perl.org
Sat Jul 11 22:07:48 GMT 2009
Author: groditi
Date: 2009-07-11 22:07:47 +0000 (Sat, 11 Jul 2009)
New Revision: 10861
Added:
Catalyst-Runtime/5.80/trunk/t/unit_core_action.t
Modified:
Catalyst-Runtime/5.80/trunk/Changes
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm
Log:
private_path method for actions that returns a string suitable for use in forward and unit tests for the rest of catalyst::Action
Modified: Catalyst-Runtime/5.80/trunk/Changes
===================================================================
--- Catalyst-Runtime/5.80/trunk/Changes 2009-07-11 19:32:11 UTC (rev 10860)
+++ Catalyst-Runtime/5.80/trunk/Changes 2009-07-11 22:07:47 UTC (rev 10861)
@@ -9,7 +9,11 @@
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
Bug fixes:
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm 2009-07-11 19:32:11 UTC (rev 10860)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Action.pm 2009-07-11 22:07:47 UTC (rev 10861)
@@ -8,6 +8,8 @@
<form action="[%c.uri_for(c.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 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 path for this action.
+=head2 private_path
+
+Returns absolute private path for this action. Unlike C<reverse>, the
+C<private_path> of an action is always suitable for passing to C<forward>.
+
=head2 name
returns the sub name of this action.
Added: Catalyst-Runtime/5.80/trunk/t/unit_core_action.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_core_action.t (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/unit_core_action.t 2009-07-11 22:07:47 UTC (rev 10861)
@@ -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');
More information about the Catalyst-commits
mailing list