Mercurial > pub > Impl
diff lib/IMPL/Object/InlineFactory.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
author | cin |
---|---|
date | Fri, 04 Sep 2015 19:40:23 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/IMPL/Object/InlineFactory.pm Fri Sep 04 19:40:23 2015 +0300 @@ -0,0 +1,44 @@ +package IMPL::Object::InlineFactory; +use strict; +use Carp qw(croak); + +sub new { + my $self = shift; + if(ref $self) { + return &$$self(@_); + } else { + my $factory = shift; + + croak "A code reference is required" + unless ref $factory eq 'CODE'; + + return bless \$factory, $self; + } +} + +1; + +__END__ + +=pod + +=head1 NAME + +C<IMPL::Object::InlineFactory> - реализация фабрики на основе процедуры. + +=head1 SYNOPSIS + +=begin code + +use IMPL::require { + InlineFactory => 'IMPL::Object::InlineFactory', + Foo => 'My::App::Foo' +}; + +my $factory = InlineFactory->new(sub { Foo->new(mode => 'direct', @_) }); + +my $obj = $factory->new(timeout => 10); # Foo->new(mode => 'direct', timeout => 10); + +=end code + +=cut \ No newline at end of file