don't exclude widgets anymore from rclass to moose helper
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Action / Role / Close.pm
CommitLineData
114916fc 1package Reaction::UI::ViewPort::Action::Role::Close;
2
3use Reaction::Role;
4use MooseX::Types::Moose qw/Str CodeRef/;
5with 'Reaction::UI::ViewPort::Action::Role::Apply';
6
7has close_label => (is => 'rw', isa => Str, lazy_build => 1);
8has on_close_callback => (is => 'rw', isa => CodeRef);
9has close_label_close => (is => 'rw', isa => Str, lazy_build => 1);
10has close_label_cancel => (is => 'rw', isa => Str, lazy_build => 1);
11
12sub _build_close_label { shift->_build_close_label_close }
13sub _build_close_label_close { 'close' }
14sub _build_close_label_cancel { 'cancel' }
15
16sub can_close { 1 }
17
18sub close {
19 my $self = shift;
20 return unless $self->has_on_close_callback;
21 $self->on_close_callback->($self);
22}
23
24around apply => sub {
25 my $orig = shift;
26 my $self = shift;
27 my $success = $self->$orig(@_);
28 $self->close_label( $self->close_label_cancel ) unless $success;
29 return $success;
30};
31
32# can't do a close-type operation if there's nowhere to go afterwards
33around accept_events => sub {
34 my $orig = shift;
35 my $self = shift;
36 ( ($self->has_on_close_callback ? ('close') : ()), $self->$orig(@_) );
37};
38
391;