documentation update, some api docs, overview and tutorial upto first DM and IM inclu...
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Action / Role / OK.pm
1 package Reaction::UI::ViewPort::Action::Role::OK;
2
3 use Reaction::Role;
4 use MooseX::Types::Moose qw/Str/;
5 with 'Reaction::UI::ViewPort::Action::Role::Close';
6
7 has ok_label => (is => 'rw', isa => 'Str', lazy_build => 1);
8
9 sub _build_ok_label { 'ok' }
10
11 sub ok {
12   my $self = shift;
13   $self->close(@_) if $self->apply(@_);
14 }
15
16 around accept_events => sub {
17   my $orig = shift;
18   my $self = shift;
19   ( ($self->has_on_close_callback ? ('ok') : ()), $self->$orig(@_) );
20 };
21
22 1;
23
24 __END__
25
26 =head1 NAME
27
28 Reaction::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
45 This role integrates an C<ok> event and inherits a 
46 L<close|Reaction::UI::ViewPort::Action::Role::Close/close>
47 and an L<apply|Reaction::UI::ViewPort::Action::Role::Apply/apply>
48 event into the consuming viewport.
49
50 =head1 ATTRIBUTES
51
52 =head2 ok_label
53
54 Defaults to C<ok>. String is built by L</_build_ok_label>.
55
56 =head1 METHODS
57
58 =head2 ok
59
60 Calls C<apply>, and then C<close> if successful.
61
62 =head2 accept_events
63
64 Extends L<Reaction::UI::ViewPort::Action::Role::Close/accept_events> with the
65 event C<ok> if an L<on_close_callback|Reaction::UI::ViewPort::Action::Role::Close/on_close_callback>
66 was provided.
67
68 =head1 INTERNAL METHODS
69
70 =head2 _build_ok_label
71
72 Returns the string representing the label for the OK action. Defaults to C<ok>.
73
74 =head1 SEE ALSO
75
76 L<Reaction::UI::ViewPort::Action::Role::Apply>
77
78 L<Reaction::UI::ViewPort::Action::Role::Close>
79
80 =head1 AUTHORS
81
82 See L<Reaction::Class> for authors.
83
84 =head1 LICENSE
85
86 See L<Reaction::Class> for the license.
87
88 =cut