annotate lib/IMPL/Object/InlineFactory.pm @ 427:09e0086a82a7 ref20150831 tip

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