Commit | Line | Data |
c8fbb8ad |
1 | package Reaction::UI::ViewPort::Action::Link; |
b8faba69 |
2 | |
3 | use Reaction::Class; |
7b5e71ad |
4 | extends 'Reaction::UI::ViewPort'; |
b8faba69 |
5 | |
81393881 |
6 | use namespace::clean -except => [ qw(meta) ]; |
7b5e71ad |
7 | use MooseX::Types::URI qw/Uri/; |
8 | use MooseX::Types::Moose qw/Object CodeRef/; |
b8faba69 |
9 | |
7b5e71ad |
10 | has uri => ( is => 'rw', isa => Uri, lazy_build => 1); |
206ce503 |
11 | has label => (is => 'rw', required => 1); |
b8faba69 |
12 | |
7b5e71ad |
13 | has target => (isa => Object, is => 'rw', required => 1); |
14 | has action => (isa => CodeRef, is => 'rw', required => 1); |
b8faba69 |
15 | |
81393881 |
16 | sub BUILD { |
17 | my $self = shift; |
18 | $self->label( $self->label->($self->target) ) if ref $self->label eq 'CODE'; |
206ce503 |
19 | } |
20 | |
81393881 |
21 | sub _build_uri { |
22 | my $self = shift; |
23 | my $c = $self->ctx; |
24 | my ($c_name, $a_name, @rest) = @{ $self->action->($self->target, $c) }; |
25 | $c->uri_for($c->controller($c_name)->action_for($a_name),@rest); |
206ce503 |
26 | } |
b8faba69 |
27 | |
81393881 |
28 | __PACKAGE__->meta->make_immutable; |
29 | |
b8faba69 |
30 | 1; |