comparison lib/IMPL/Object/InlineFactory.pm @ 407:c6e90e02dd17 ref20150831

renamed Lib->lib
author cin
date Fri, 04 Sep 2015 19:40:23 +0300
parents
children
comparison
equal deleted inserted replaced
406:f23fcb19d3c1 407:c6e90e02dd17
1 package IMPL::Object::InlineFactory;
2 use strict;
3 use Carp qw(croak);
4
5 sub new {
6 my $self = shift;
7 if(ref $self) {
8 return &$$self(@_);
9 } else {
10 my $factory = shift;
11
12 croak "A code reference is required"
13 unless ref $factory eq 'CODE';
14
15 return bless \$factory, $self;
16 }
17 }
18
19 1;
20
21 __END__
22
23 =pod
24
25 =head1 NAME
26
27 C<IMPL::Object::InlineFactory> - реализация фабрики на основе процедуры.
28
29 =head1 SYNOPSIS
30
31 =begin code
32
33 use IMPL::require {
34 InlineFactory => 'IMPL::Object::InlineFactory',
35 Foo => 'My::App::Foo'
36 };
37
38 my $factory = InlineFactory->new(sub { Foo->new(mode => 'direct', @_) });
39
40 my $obj = $factory->new(timeout => 10); # Foo->new(mode => 'direct', timeout => 10);
41
42 =end code
43
44 =cut