Gapp

 view release on metacpan or  search on metacpan

lib/Gapp/Actions.pm  view on Meta::CPAN

package Gapp::Actions;
{
  $Gapp::Actions::VERSION = '0.60';
}
use Moose;

use Gapp::Actions::Base;
use Gapp::Actions::Util;
use Carp::Clan qw( ^Gapp::Actions );
use Sub::Name;

use namespace::clean -except => [qw( meta )];

sub import {
    my ($class, %args) = @_;
    my  $callee = caller;

    strict->import;
    warnings->import;

    # inject base class into new library
    {   no strict 'refs';
        unshift @{ $callee . '::ISA' }, 'Gapp::Actions::Base';
    }

    # generate predeclared action helpers
    if (my @orig_declare = @{ $args{ -declare } || [] }) {
        my @to_export;
        
        for my $action (@orig_declare) {
            
            croak q[could not create action ($action): actions may not contain '::']
                if $action =~ /::/;
            
            # add action to library and remember to export
            $callee->declare_action( $action );
            push @to_export, $action;
        }
        
        $callee->import({ -full => 1, -into => $callee }, @to_export);
    }

    Gapp::Actions::Util->import({ into => $callee });

    1;
}


sub action_export_generator {
    my ( $class, $caller, $name ) = @_;
    
    return subname "__ACTION__::" . $caller . "::" . "$name" => sub {
        return ACTION_REGISTRY( $caller )->action( $name );
    };
}

sub perform_export_generator {
    my ( $class, $caller, $name ) = @_;
    
    return sub {
        my $action = ACTION_REGISTRY( $caller )->action( $name );
        return $action->code->( $action, @_ );
    };
}

1;


__END__

=pod

=head1 NAME

Gapp::Actions - Create Actions for Gapp Applications

=head1 SYNOPSIS



( run in 2.454 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )