WebApp/Factory.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 100% 58 / 58 CC 5 SCAR 6.2
CC
5
Cov
100%
type
3.0
load_types_class
3.0
BEGIN
1.0
CRAP 1.9
« WebApp/Segment/User/RequestLoader.pm ↑ Summary WebApp/Template/Factory.pm »
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 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 9 ▶use Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶use OpenFrame::WebApp::Error::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶use OpenFrame::WebApp::Error::LoadClass;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 9 ▶use base qw ( OpenFrame::Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 9 our $VERSION = (split(/ /, '$Revision: 1.5 $'))[1];
28  
29 33 ▶sub type {
Subroutine type: called CC=3 SCAR=11.0
Pod documented
30 33 my $self = shift;
31 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 10 23 33
32 10 $self->{object_type} = shift;
33 10 ▶ $self->error( "warning: $self->{object_type} has no known class!" )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_types_class 1 9 10
34 unless ($self->get_types_class);
35 10 return $self;
36 } else {
37 23 return $self->{object_type};
38 }
39 }
40  
41 1 ▶sub get_types_class {
Subroutine get_types_class: called CC=1 SCAR=0.0
Pod documented
42 1 my $self = shift;
43 1 throw OpenFrame::WebApp::Error::Abstract( class => ref($self) );
44 }
45  
46 10 ▶sub new_object {
Subroutine new_object: called CC=1 SCAR=0.0
Pod documented
47 10 my $self = shift;
48 10 return $self->load_types_class->new( @_ );
49 }
50  
51 14 ▶sub load_types_class {
Subroutine load_types_class: called CC=3 SCAR=11.0
Pod documented
52 14 my $self = shift;
53 14 my $class = $self->get_types_class;
54 14 ▶ unless ( $class->can( 'new' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->can("new")) 2 12 14
55 2 eval "require $class;";
56 2 ▶ throw OpenFrame::WebApp::Error::LoadClass( -text => $@ ) if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 1 2
57 }
58 13 return $class;
59 }
60  
61 9 1;
62  
63 __END__
« WebApp/Segment/User/RequestLoader.pm ↑ Summary WebApp/Template/Factory.pm »