Commit | Line | Data |
a42fd357 |
1 | package CatalystX::UriFor::Curried; |
c575a0d7 |
2 | use MooseX::Role::Parameterized; |
3 | use Moose::Autobox; |
4 | use MooseX::Types::Moose qw/ Str ArrayRef /; |
5 | use Scalar::Util qw/ weaken /; |
a42fd357 |
6 | use namespace::autoclean; |
7 | |
c575a0d7 |
8 | parameter method_name => ( |
9 | isa => Str, |
10 | required => 1, |
11 | ); |
12 | |
13 | parameter stash_captures => ( |
14 | isa => ArrayRef[Str], |
15 | required => 1, |
16 | ); |
17 | |
18 | role { |
19 | my $p = shift; |
20 | |
21 | my $method_name = $p->method_name; |
22 | my $stash_captures => $p->stash_captures; |
23 | |
24 | method $method_name => sub { |
25 | my ($ctx, $action_or_private_path, $captures, @args) = @_; |
26 | my $weak_ctx = $ctx; # Just for safety so it can't be closed over. |
27 | weaken($weak_ctx); |
28 | if (ref($captures) eq 'ARRAY' || (!$captures && !scalar(@args))) { # FIXME BUG IN THIS LOGIC |
29 | $captures ||= []; |
30 | foreach my $name_or_sub ($stash_captures->flatten) { |
31 | unshift(@$captures, ref($name_or_sub) eq 'CODE' ? $name_or_sub->($weak_ctx) : $ctx->stash->{$name_or_sub}); |
32 | } |
33 | $ctx->uri_for_action($action_or_private_path, $captures, @args); |
34 | } |
35 | }; |
36 | |
37 | }; |
38 | |
a42fd357 |
39 | 1; |
40 | |
41 | =head1 NAME |
42 | |
43 | CatalystX::UriFor::Curried - |
44 | |
45 | =head1 DESCRIPTION |
46 | |
47 | =head1 METHODS |
48 | |
49 | =head1 BUGS |
50 | |
51 | =head1 AUTHOR |
52 | |
53 | =head1 COPYRIGHT & LICENSE |
54 | |
55 | Copyright 2009 the above author(s). |
56 | |
57 | This sofware is free software, and is licensed under the same terms as perl itself. |
58 | |
59 | =cut |
60 | |