Reaction::UI::ViewPort::Action::Role::Close - Integrate Close and Apply events into ViewPort


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::ViewPort::Action::Role::Close - Integrate Close and Apply events into ViewPort

SYNOPSIS

Top

  package MyApp::UI::ViewPort::SomeAction;
  use Reaction::Class;

  use namespace::clean -except => 'meta';

  extends 'Reaction::UI::ViewPort::Object::Mutable';
  with    'Reaction::UI::ViewPort::Action::Role::Close';

  ...
  1;

DESCRIPTION

Top

This role integrates a close event and inherits an apply event into the consuming viewport.

ATTRIBUTES

Top

close_label

Defaults to returned string value of _build_close_label (close).

close_label_close

Defaults to returned string value of _build_close_label_close (close).

close_label_cancel

This label is only shown when changed is true. It is initialised with the returned string value of _build_close_label_cancel.

Default: 'cancel'

on_close_callback

CodeRef. If set will be called on close.

METHODS

Top

close

Calls on_close_callback if one is set.

can_close

Returns true.

apply

Extends apply in Reaction::UI::ViewPort::Action::Role::Apply and sets the close_label to close_label_cancel if the original call to apply was not successfull.

Returns the result of the original apply call.

accept_events

Extends accept_events in Reaction::UI::ViewPort::Action::Role::Apply with the close event if an on_close_callback was provided.

SEE ALSO

Top

Reaction::UI::ViewPort::Action::Role::Apply

Reaction::UI::ViewPort::Action::Role::OK

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::UI::ViewPort::Action::Role::Close;

use Reaction::Role;
use MooseX::Types::Moose qw/Str CodeRef/;
with 'Reaction::UI::ViewPort::Action::Role::Apply';

has close_label => (is => 'rw', isa => Str, lazy_build => 1);
has on_close_callback => (is => 'rw', isa => CodeRef);
has close_label_close => (is => 'rw', isa => Str, lazy_build => 1);
has close_label_cancel => (is => 'rw', isa => Str, lazy_build => 1);

sub _build_close_label { shift->_build_close_label_close }
sub _build_close_label_close { 'close' }
sub _build_close_label_cancel { 'cancel' }

sub can_close { 1 }

sub close {
  my $self = shift;
  return unless $self->has_on_close_callback;
  $self->on_close_callback->($self);
}

around apply => sub {
  my $orig = shift;
  my $self = shift;
  my $success = $self->$orig(@_);
  $self->close_label( $self->close_label_cancel ) unless $success;
  return $success;
};

# can't do a close-type operation if there's nowhere to go afterwards
around accept_events => sub {
  my $orig = shift;
  my $self = shift;
  ( ($self->has_on_close_callback ? ('close') : ()), $self->$orig(@_) );
};

1;

__END__