| 1 | package Excel::Template::Factory; | ||||||||||
| 2 | |||||||||||
| 3 | 30 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 30 | my %Manifest = ( | |||||||||
| 6 | |||||||||||
| 7 | # These are the instantiable nodes | ||||||||||
| 8 | 'IF' => 'Excel::Template::Container::Conditional', | ||||||||||
| 9 | 'LOOP' => 'Excel::Template::Container::Loop', | ||||||||||
| 10 | 'ROW' => 'Excel::Template::Container::Row', | ||||||||||
| 11 | 'SCOPE' => 'Excel::Template::Container::Scope', | ||||||||||
| 12 | 'WORKBOOK' => 'Excel::Template::Container::Workbook', | ||||||||||
| 13 | 'WORKSHEET' => 'Excel::Template::Container::Worksheet', | ||||||||||
| 14 | |||||||||||
| 15 | 'BACKREF' => 'Excel::Template::Element::Backref', | ||||||||||
| 16 | 'CELL' => 'Excel::Template::Element::Cell', | ||||||||||
| 17 | 'FORMULA' => 'Excel::Template::Element::Formula', | ||||||||||
| 18 | 'FREEZEPANES' => 'Excel::Template::Element::FreezePanes', | ||||||||||
| 19 | 'MERGE_RANGE' => 'Excel::Template::Element::MergeRange', | ||||||||||
| 20 | 'IMAGE' => 'Excel::Template::Element::Image', | ||||||||||
| 21 | 'RANGE' => 'Excel::Template::Element::Range', | ||||||||||
| 22 | 'VAR' => 'Excel::Template::Element::Var', | ||||||||||
| 23 | |||||||||||
| 24 | 'FORMAT' => 'Excel::Template::Container::Format', | ||||||||||
| 25 | |||||||||||
| 26 | # These are all the Format short-cut objects | ||||||||||
| 27 | # They are also instantiable | ||||||||||
| 28 | 'BOLD' => 'Excel::Template::Container::Bold', | ||||||||||
| 29 | 'HIDDEN' => 'Excel::Template::Container::Hidden', | ||||||||||
| 30 | 'ITALIC' => 'Excel::Template::Container::Italic', | ||||||||||
| 31 | 'LOCKED' => 'Excel::Template::Container::Locked', | ||||||||||
| 32 | 'OUTLINE' => 'Excel::Template::Container::Outline', | ||||||||||
| 33 | 'SHADOW' => 'Excel::Template::Container::Shadow', | ||||||||||
| 34 | 'STRIKEOUT' => 'Excel::Template::Container::Strikeout', | ||||||||||
| 35 | |||||||||||
| 36 | 'KEEP_LEADING_ZEROS' => 'Excel::Template::Container::KeepLeadingZeros', | ||||||||||
| 37 | |||||||||||
| 38 | # These are the helper objects | ||||||||||
| 39 | # They are also in here to make E::T::Factory::isa() work. | ||||||||||
| 40 | 'CONTEXT' => 'Excel::Template::Context', | ||||||||||
| 41 | 'ITERATOR' => 'Excel::Template::Iterator', | ||||||||||
| 42 | 'TEXTOBJECT' => 'Excel::Template::TextObject', | ||||||||||
| 43 | |||||||||||
| 44 | 'CONTAINER' => 'Excel::Template::Container', | ||||||||||
| 45 | 'ELEMENT' => 'Excel::Template::Element', | ||||||||||
| 46 | |||||||||||
| 47 | 'BASE' => 'Excel::Template::Base', | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | 30 | my %isBuildable = map { $_ => ~~1 } qw( | |||||||||
| 51 | WORKBOOK WORKSHEET | ||||||||||
| 52 | FORMAT BOLD HIDDEN ITALIC LOCKED OUTLINE SHADOW STRIKEOUT | ||||||||||
| 53 | IF ROW LOOP SCOPE KEEP_LEADING_ZEROS | ||||||||||
| 54 | CELL FORMULA FREEZEPANES IMAGE MERGE_RANGE | ||||||||||
| 55 | VAR BACKREF RANGE | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | { | ||||||||||
| 59 | 30 | my %Loaded; | |||||||||
| 60 | sub _load_class | ||||||||||
| 61 | { | ||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_load_class: not called CC=3 SCAR=24.8
| |||||||||||
| 63 | 0 | my ($class) = @_; | |||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | unless ( exists $Loaded{$class} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | { | ||||||||||
| 67 | 0 | (my $filename = $class) =~ s!::!/!g; | |||||||||
| 68 | 0 | eval { | |||||||||
| 69 | 0 | require "$filename.pm"; | |||||||||
| 70 | 0 | ▶ | }; if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | die "Cannot find or compile PM file for '$class' ($filename) because $@\n"; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 0 | $Loaded{$class} = ~~1; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | return ~~1; | |||||||||
| 78 | } | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | { | ||||||||||
| 82 | 30 | my @param_names = qw(name class isa); | |||||||||
| 83 | sub register | ||||||||||
| 84 | { | ||||||||||
| 85 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
register: not called CC=8 SCAR=40.5
Pod
documented
| |||||||||||
| 86 | 0 | my %params = @_; | |||||||||
| 87 | |||||||||||
| 88 | 0 | for (@param_names) | |||||||||
| 89 | { | ||||||||||
| 90 | 0 | ▶ | unless ($params{$_}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | { | ||||||||||
| 92 | 0 | ▶ | warn "$_ was not supplied to register()\n" if $^W; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | 0 | return; | |||||||||
| 94 | } | ||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | my $name = uc $params{name}; | |||||||||
| 98 | 0 | ▶ | if (exists $Manifest{$name}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | { | ||||||||||
| 100 | 0 | ▶ | warn "$params{name} already exists in the manifest.\n" if $^W; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | return; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | my $isa = uc $params{isa}; | |||||||||
| 105 | 0 | ▶ | unless (exists $Manifest{$isa}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | { | ||||||||||
| 107 | 0 | ▶ | warn "$params{isa} does not exist in the manifest.\n" if $^W; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | return; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | { | ||||||||||
| 112 | 30 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||
| 113 | 0 | unshift @{"$params{class}::ISA"}, $Manifest{$isa}; | |||||||||
| 114 | } | ||||||||||
| 115 | |||||||||||
| 116 | 0 | $self->_load_class( $Manifest{$isa} ); | |||||||||
| 117 | 0 | $self->_load_class( $params{class} ); | |||||||||
| 118 | |||||||||||
| 119 | 0 | $Manifest{$name} = $params{class}; | |||||||||
| 120 | 0 | $isBuildable{$name} = ~~1; | |||||||||
| 121 | |||||||||||
| 122 | 0 | return ~~1; | |||||||||
| 123 | } | ||||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | sub _create | ||||||||||
| 127 | 30 | { | |||||||||
| 128 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_create: not called CC=2 SCAR=17.9
| |||||||||||
| 129 | 0 | my $name = uc shift; | |||||||||
| 130 | |||||||||||
| 131 | 0 | ▶ | return unless exists $Manifest{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 132 | |||||||||||
| 133 | 0 | $self->_load_class( $Manifest{$name} ); | |||||||||
| 134 | |||||||||||
| 135 | 0 | return $Manifest{$name}->new(@_); | |||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | sub _create_node | ||||||||||
| 139 | { | ||||||||||
| 140 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_create_node: not called CC=2 SCAR=17.9
| |||||||||||
| 141 | 0 | my $name = uc shift; | |||||||||
| 142 | |||||||||||
| 143 | 0 | ▶ | return unless exists $isBuildable{$name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | |||||||||||
| 145 | 0 | return $self->_create($name, @_); | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | sub isa | ||||||||||
| 149 | { | ||||||||||
| 150 | 28 | ▶ | return unless @_ >= 2; | ||||||||
|
Subroutine
isa: called CC=3 SCAR=12.0
Pod
documented
Branch: 1 branch
| |||||||||||
| 151 | exists $Manifest{uc $_[1]} | ||||||||||
| 152 | 28 | ▶ | ? UNIVERSAL::isa($_[0], $Manifest{uc $_[1]}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 153 | : UNIVERSAL::isa(@_) | ||||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | sub is_embedded | ||||||||||
| 157 | { | ||||||||||
| 158 | 0 | ▶ | return unless @_ >= 1; | ||||||||
|
Subroutine
is_embedded: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||
| 159 | |||||||||||
| 160 | 0 | ▶ | isa( $_[0], $_ ) && return ~~1 for qw( VAR BACKREF RANGE ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 161 | 0 | return; | |||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | 30 | 1; | |||||||||
| 165 | __END__ | ||||||||||