line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
OpenFrame::WebApp::Factory - abstract factory class |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# abstract class - must override to use |
8
|
|
|
|
|
|
|
use OpenFrame::WebApp::Factory::Foo; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $factory = new OpenFrame::WebApp::Factory::Foo()->type('bar'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $obj = $factory->new_object( @args ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package OpenFrame::WebApp::Factory; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
35672
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
19
|
1
|
|
|
1
|
|
9
|
use warnings::register; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
161
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
6
|
use Error; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
22
|
1
|
|
|
1
|
|
627
|
use OpenFrame::WebApp::Error::Abstract; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
23
|
1
|
|
|
1
|
|
801
|
use OpenFrame::WebApp::Error::LoadClass; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
53
|
use base qw ( OpenFrame::Object ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
912
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = (split(/ /, '$Revision: 1.5 $'))[1]; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub type { |
30
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
if (@_) { |
32
|
|
|
|
|
|
|
$self->{object_type} = shift; |
33
|
|
|
|
|
|
|
$self->error( "warning: $self->{object_type} has no known class!" ) |
34
|
|
|
|
|
|
|
unless ($self->get_types_class); |
35
|
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} else { |
37
|
|
|
|
|
|
|
return $self->{object_type}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get_types_class { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
throw OpenFrame::WebApp::Error::Abstract( class => ref($self) ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new_object { |
47
|
|
|
|
|
|
|
my $self = shift; |
48
|
|
|
|
|
|
|
return $self->load_types_class->new( @_ ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub load_types_class { |
52
|
|
|
|
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
my $class = $self->get_types_class; |
54
|
|
|
|
|
|
|
unless ( $class->can( 'new' ) ) { |
55
|
|
|
|
|
|
|
eval "require $class;"; |
56
|
|
|
|
|
|
|
throw OpenFrame::WebApp::Error::LoadClass( -text => $@ ) if ($@); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
return $class; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |