Reaction::UI::ViewPort::Action::Role::Apply - Integrate an Apply event into the ViewPort


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::ViewPort::Action::Role::Apply - Integrate an Apply event into the 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::Apply';

  ...
  1;

DESCRIPTION

Top

This role integrates an apply event into the consuming viewport that will call the required do_apply role.

REQUIRED METHODS

Top

do_apply

Will be called when an apply event comes in.

ATTRIBUTES

Top

apply_label

Defaults to 'apply', returned by _build_apply_label.

on_apply_callback

CodeRef. Will be called after apply if can_apply and do_apply return true. See apply for argument details.

METHODS

Top

can_apply

Returns true by default. Determines if do_apply can be called.

apply

Calls a user-supplied do_apply and if it is successful runs the on_apply_callback passing $self and the result of do_apply as args.

INTERNAL METHODS

Top

_build_apply_label

Defaults to apply.

SEE ALSO

Top

Reaction::UI::ViewPort::Action::Role::Close

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::Apply;

use Reaction::Role;
use MooseX::Types::Moose qw/Str CodeRef/;

requires 'do_apply';
has apply_label => (is => 'rw', isa => Str, lazy_build => 1);
has on_apply_callback => (is => 'rw', isa => CodeRef);

sub _build_apply_label { 'apply' }

sub can_apply { 1 }

sub apply {
  my $self = shift;
  if ($self->can_apply && (my $result = $self->do_apply)) {
    $self->on_apply_callback->($self => $result) if $self->has_on_apply_callback;
    return 1;
  } else {
    if( my $coderef = $self->can('close_label') ){
      $self->$coderef( $self->close_label_cancel );
    }
    return 0;
  }
};

around accept_events => sub { ( 'apply', shift->(@_) ) };

1;

__END__