Workflow

 view release on metacpan or  search on metacpan

lib/Workflow/Factory.pm  view on Meta::CPAN

    $class = ref $class || $class;    # just in case
    my $package = caller;
    my $log = get_logger(__PACKAGE__);
    if ( defined $_[0] && $_[0] eq 'FACTORY' ) {
        shift;
        my $instance;

        my $import_target = $package . '::FACTORY';
        no strict 'refs';
        unless ( defined &{$import_target} ) {
            *{$import_target} = sub {
                return $instance if $instance;
                $instance = _initialize_instance($class);
                return $instance;
            };
        }
    }
    $class->SUPER::import(@_);
}

require Workflow;
require Workflow::Action;
require Workflow::Condition;
require Workflow::Condition::Negated;
require Workflow::Config;
require Workflow::Context;
require Workflow::History;
require Workflow::Persister;
require Workflow::State;
require Workflow::Validator;

my $DEFAULT_INITIAL_STATE = 'INITIAL';

my @FIELDS = qw(config_callback);

__PACKAGE__->mk_accessors(@FIELDS);

sub new {
    my $proto = shift;
    my $class = ref $proto || $proto;

    workflow_error "Please call 'instance()' or import the 'FACTORY' object ",
        "to get the '$class' object rather than instantiating a ",
        "new one directly.";
}

sub instance {
    my $proto = shift;
    my $class = ref $proto || $proto;

    return _initialize_instance($class);
}

sub _initialize_instance {
    my ($class) = @_;

    my $log = get_logger(__PACKAGE__);
    unless ( $INSTANCES{$class} ) {
        $log->debug( "Creating empty instance of '$class' factory for ",
                     "singleton use" );
        my $instance = bless {} => $class;
        $instance->init();
        $INSTANCES{$class} = $instance;
    }
    return $INSTANCES{$class};
}

sub _delete_instance {
    my ($class) = @_;

    my $log = get_logger(__PACKAGE__);
    if ( $INSTANCES{$class} ) {
        $log->debug( "Deleting instance of '$class' factory." );
        delete $INSTANCES{$class};
    } else {
        $log->debug( "No instance of '$class' factory found." );
    }

    return;
}

my %CONFIG = ( 'Workflow::Config' => 1 );

sub add_config_from_file {
    my ( $self, %params ) = @_;
    return unless ( scalar keys %params );

    _check_config_keys(%params);

    foreach my $type ( sort keys %params ) {
        $self->log->debug(
            sub { "Using '$type' configuration file(s): " .
                      join( ', ', _flatten( $params{$type} ) ) } );
    }

    $self->log->debug( "Adding condition configurations..." );

    if ( ref $params{condition} eq 'ARRAY' ) {
        foreach my $condition ( @{ $params{condition} } ) {
            $self->_add_condition_config(
                Workflow::Config->parse_all_files( 'condition', $condition )
            );
        }
    } else {
        $self->_add_condition_config(
            Workflow::Config->parse_all_files(
                'condition', $params{condition}
            )
        );
    }

    $self->log->debug( "Adding validator configurations..." );

    if ( ref $params{validator} eq 'ARRAY' ) {
        foreach my $validator ( @{ $params{validator} } ) {
            $self->_add_validator_config(
                Workflow::Config->parse_all_files( 'validator', $validator )
            );
        }
    } else {
        $self->_add_validator_config(

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.706 second using v1.00-cache-2.02-grep-82fe00e-cpan-cec75d87357c )