| 1 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | package Class::Factory::Enhanced; | ||||||||||||||||||||
| 6 | 2 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | $Class::Factory::Enhanced::VERSION = '1.101420'; | |||||||||||||||||||
| 8 | } | ||||||||||||||||||||
| 9 | # ABSTRACT: More functionality for Class::Factory | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | ▶ | use parent 'Class::Factory'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | # add support for defining several mappings at once | ||||||||||||||||||||
| 14 | 2 | ▶ | sub add_factory_type { | ||||||||||||||||||
|
Subroutine
add_factory_type: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||
| 15 | 2 | my ($item, @args) = @_; | |||||||||||||||||||
| 16 | 2 | ▶ | my $class = ref $item || $item; | ||||||||||||||||||
|
Condition33%1/3
ref $item || $item
MC/DC0%0/2
ref $item || $item
ref $item
$item
Truth table33%1/3
A || B
A= ref $itemB= $item
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # SUPER::add_factory_type, which only allows one mapping, returns the | ||||||||||||||||||||
| 19 | # object class. The return value is not used when defining the mappings, | ||||||||||||||||||||
| 20 | # but it is used in get_factory_class(). get_factory_class() only calls | ||||||||||||||||||||
| 21 | # this with one argument, so return the first object class we see. It's a | ||||||||||||||||||||
| 22 | # hack, yes... | ||||||||||||||||||||
| 23 | 2 | my $first_object_class; | |||||||||||||||||||
| 24 | 2 | ▶ | while (my ($object_type, $object_class) = splice @args, 0, 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | 2 | $class->SUPER::remove_factory_type($object_type); | |||||||||||||||||||
| 26 | 2 | $class->SUPER::add_factory_type($object_type, $object_class); | |||||||||||||||||||
| 27 | 2 | ▶ | $first_object_class ||= $object_class; | ||||||||||||||||||
|
Condition33%1/3
$first_object_class ||= $object_class
MC/DC0%0/2
$first_object_class ||= $object_class
$first_object_class
$object_class
Truth table33%1/3
A ||= B
A= $first_object_classB= $object_class
| |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 2 | return $first_object_class; | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | ▶ | sub register_factory_type { | ||||||||||||||||||
|
Subroutine
register_factory_type: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 33 | 2 | my ($item, @args) = @_; | |||||||||||||||||||
| 34 | 2 | ▶ | my $class = ref $item || $item; | ||||||||||||||||||
|
Condition33%1/3
ref $item || $item
MC/DC0%0/2
ref $item || $item
ref $item
$item
Truth table33%1/3
A || B
A= ref $itemB= $item
| |||||||||||||||||||||
| 35 | 2 | ▶ | while (my ($object_type, $object_class) = splice @args, 0, 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 4 | $class->SUPER::unregister_factory_type($object_type); | |||||||||||||||||||
| 37 | 4 | $class->SUPER::register_factory_type($object_type, $object_class); | |||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 2 | ▶ | sub make_object_for_type { | ||||||||||||||||||
|
Subroutine
make_object_for_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 42 | 2 | my ($self, $object_type, @args) = @_; | |||||||||||||||||||
| 43 | 2 | my $class = $self->get_factory_class($object_type); | |||||||||||||||||||
| 44 | 2 | $class->new(@args); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||