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