1 package Reaction::UI::ViewPort::Action::Role::Close;
4 use MooseX::Types::Moose qw/Str CodeRef/;
5 with 'Reaction::UI::ViewPort::Action::Role::Apply';
7 has close_label => (is => 'rw', isa => Str, lazy_build => 1);
8 has on_close_callback => (is => 'rw', isa => CodeRef);
9 has close_label_close => (is => 'rw', isa => Str, lazy_build => 1);
10 has close_label_cancel => (is => 'rw', isa => Str, lazy_build => 1);
12 sub _build_close_label { shift->_build_close_label_close }
13 sub _build_close_label_close { 'close' }
14 sub _build_close_label_cancel { 'cancel' }
20 return unless $self->has_on_close_callback;
21 $self->on_close_callback->($self);
27 my $success = $self->$orig(@_);
28 $self->close_label( $self->close_label_cancel ) unless $success;
32 # can't do a close-type operation if there's nowhere to go afterwards
33 around accept_events => sub {
36 ( ($self->has_on_close_callback ? ('close') : ()), $self->$orig(@_) );
45 Reaction::UI::ViewPort::Action::Role::Close - Integrate Close and Apply events into ViewPort
49 package MyApp::UI::ViewPort::SomeAction;
52 use namespace::clean -except => 'meta';
54 extends 'Reaction::UI::ViewPort::Object::Mutable';
55 with 'Reaction::UI::ViewPort::Action::Role::Close';
62 This role integrates a C<close> event and inherits an
63 L<apply|Reaction::UI::ViewPort::Action::Role::Close/apply>
64 event into the consuming viewport.
70 Defaults to returned string value of L</_build_close_label> (C<close>).
72 =head2 close_label_close
74 Defaults to returned string value of L</_build_close_label_close> (C<close>).
76 =head2 close_label_cancel
78 This label is only shown when C<changed> is true. It is initialised
79 with the returned string value of L</_build_close_label_cancel>.
83 =head2 on_close_callback
85 CodeRef. If set will be called on L</close>.
91 Calls L</on_close_callback> if one is set.
99 Extends L<Reaction::UI::ViewPort::Action::Role::Apply/apply> and sets
100 the L</close_label> to L</close_label_cancel> if the original call to
101 C<apply> was not successfull.
103 Returns the result of the original C<apply> call.
107 Extends L<Reaction::UI::ViewPort::Action::Role::Apply/accept_events>
108 with the C<close> event if an L</on_close_callback> was provided.
112 L<Reaction::UI::ViewPort::Action::Role::Apply>
114 L<Reaction::UI::ViewPort::Action::Role::OK>
118 See L<Reaction::Class> for authors.
122 See L<Reaction::Class> for the license.