do not include .git directory
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Action / Role / OK.pm
CommitLineData
114916fc 1package Reaction::UI::ViewPort::Action::Role::OK;
2
3use Reaction::Role;
4use MooseX::Types::Moose qw/Str/;
5with 'Reaction::UI::ViewPort::Action::Role::Close';
6
7b5e71ad 7has ok_label => (is => 'rw', isa => Str, lazy_build => 1);
114916fc 8
9sub _build_ok_label { 'ok' }
10
11sub ok {
12 my $self = shift;
13 $self->close(@_) if $self->apply(@_);
14}
15
16around accept_events => sub {
17 my $orig = shift;
18 my $self = shift;
1d6ef3dc 19 ( ($self->has_on_close_callback ? ('ok') : ()), $self->$orig(@_) );
114916fc 20};
21
221;
7826ddac 23
24__END__
25
26=head1 NAME
27
63bb30b4 28Reaction::UI::ViewPort::Action::Role::OK - Integrate OK, Apply and Close events
29
30=head1 SYNOPSIS
31
32 package MyApp::UI::ViewPort::SomeAction;
33 use Reaction::Class;
34
35 use namespace::clean -except => 'meta';
36
37 extends 'Reaction::UI::ViewPort::Object::Mutable';
38 with 'Reaction::UI::ViewPort::Action::Role::OK';
39
40 ...
41 1;
42
43=head1 DESCRIPTION
44
45This role integrates an C<ok> event and inherits a
46L<close|Reaction::UI::ViewPort::Action::Role::Close/close>
47and an L<apply|Reaction::UI::ViewPort::Action::Role::Apply/apply>
48event into the consuming viewport.
7826ddac 49
50=head1 ATTRIBUTES
51
52=head2 ok_label
53
63bb30b4 54Defaults to C<ok>. String is built by L</_build_ok_label>.
7826ddac 55
56=head1 METHODS
57
58=head2 ok
59
60Calls C<apply>, and then C<close> if successful.
61
63bb30b4 62=head2 accept_events
63
64Extends L<Reaction::UI::ViewPort::Action::Role::Close/accept_events> with the
65event C<ok> if an L<on_close_callback|Reaction::UI::ViewPort::Action::Role::Close/on_close_callback>
66was provided.
67
68=head1 INTERNAL METHODS
69
70=head2 _build_ok_label
71
72Returns the string representing the label for the OK action. Defaults to C<ok>.
73
7826ddac 74=head1 SEE ALSO
75
76L<Reaction::UI::ViewPort::Action::Role::Apply>
77
78L<Reaction::UI::ViewPort::Action::Role::Close>
79
80=head1 AUTHORS
81
82See L<Reaction::Class> for authors.
83
84=head1 LICENSE
85
86See L<Reaction::Class> for the license.
87
88=cut