X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FAction.pm;h=cd2d008118f64efd8eda44c8cc88bb53e77c9363;hp=e2e78b689156976a5c5a5341dbedcbaaf98b9fac;hb=2efad04b4d6590ecf00566d698e94622198909aa;hpb=536bee890cf24e0e4bcda7562e7b70cc03ca0620 diff --git a/lib/Catalyst/Action.pm b/lib/Catalyst/Action.pm index e2e78b6..cd2d008 100644 --- a/lib/Catalyst/Action.pm +++ b/lib/Catalyst/Action.pm @@ -18,8 +18,9 @@ L subclasses. =cut use Moose; - +use Scalar::Util 'looks_like_number'; with 'MooseX::Emulate::Class::Accessor::Fast'; +use namespace::clean -except => 'meta'; has class => (is => 'rw'); has namespace => (is => 'rw'); @@ -28,8 +29,6 @@ has attributes => (is => 'rw'); has name => (is => 'rw'); has code => (is => 'rw'); -no Moose; - use overload ( # Stringify to reverse for debug output etc. @@ -70,6 +69,18 @@ sub match { return scalar( @{ $c->req->args } ) == $args; } +sub compare { + my ($a1, $a2) = @_; + + my ($a1_args) = @{ $a1->attributes->{Args} || [] }; + my ($a2_args) = @{ $a2->attributes->{Args} || [] }; + + $_ = looks_like_number($_) ? $_ : ~0 + for $a1_args, $a2_args; + + return $a1_args <=> $a2_args; +} + __PACKAGE__->meta->make_immutable; 1; @@ -105,6 +116,11 @@ context and arguments Check Args attribute, and makes sure number of args matches the setting. Always returns true if Args is omitted. +=head2 compare + +Compares 2 actions based on the value of the C attribute, with no C +having the highest precedence. + =head2 namespace Returns the private namespace this action lives in.