annotate Lib/IMPL/Object/InlineFactory.pm @ 373:3ca44e23fd1f

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