| 1 | package Treex::PML::Factory; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 9 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 9 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 9 | $VERSION='2.29'; # version template | |||||||||||||||||||
| 10 | } | ||||||||||||||||||||
| 11 | 9 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 9 | ▶ | use UNIVERSAL::DOES; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 9 | my $default_factory; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 9 | ▶ | sub DOES { | ||||||||||||||||||
|
Subroutine
DOES: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||
| 17 | 9 | my ($self,$role)=@_; | |||||||||||||||||||
| 18 | 9 | ▶ | if ($role eq __PACKAGE__) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | # we don't implement Treex::PML::Factory interface, but anything derived from use is assumed to do so | ||||||||||||||||||||
| 20 | 9 | ▶ | return ref($role) eq __PACKAGE__ ? 0 : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | } else { | ||||||||||||||||||||
| 22 | 0 | return $self->DOES($role); | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 9 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 27 | 9 | my $class = shift; | |||||||||||||||||||
| 28 | 9 | return bless {@_}, $class; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 9 | ▶ | sub make_default { | ||||||||||||||||||
|
Subroutine
make_default: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||
| 32 | 9 | my $obj = shift; | |||||||||||||||||||
| 33 | 9 | ▶ | my $class = ref($obj) || $obj; | ||||||||||||||||||
|
Condition33%1/3
ref $obj || $obj
MC/DC0%0/2
ref $obj || $obj
ref $obj
$obj
Truth table33%1/3
A || B
A= ref $objB= $obj
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 9 | ▶ | die __PACKAGE__." is not a proper factory and cannot be made default!\n" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | if $class eq __PACKAGE__; | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 9 | my $prev = Treex::PML::Factory->get_default_factory; | |||||||||||||||||||
| 39 | 9 | ▶ | unless ((ref($prev)||'') eq $class) { | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
ref $prev || ''
MC/DC0%0/1
ref $prev || ''
ref $prev
Truth table50%1/2
A
A= ref $prev
| |||||||||||||||||||||
| 40 | 9 | ▶ | Treex::PML::Factory->set_default_factory(ref($obj) ? $obj : $class->new(@_)); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | 9 | return $prev; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 9 | ▶ | sub set_default_factory { | ||||||||||||||||||
|
Subroutine
set_default_factory: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 46 | 9 | my ($self,$factory)=@_; | |||||||||||||||||||
| 47 | 9 | ▶ | die __PACKAGE__."->set_default_factory: argument must implement ".__PACKAGE__."!" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | unless UNIVERSAL::DOES::does($factory,__PACKAGE__); | ||||||||||||||||||||
| 49 | 9 | $default_factory = $factory; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 9 | ▶ | sub get_default_factory { | ||||||||||||||||||
|
Subroutine
get_default_factory: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 53 | 9 | return $default_factory; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 9 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 57 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | 9 | for my $method (qw( | |||||||||||||||||||
| 59 | createPMLSchema createPMLInstance | ||||||||||||||||||||
| 60 | createDocument createDocumentFromFile | ||||||||||||||||||||
| 61 | createFSFormat | ||||||||||||||||||||
| 62 | createNode createTypedNode createList createSeq | ||||||||||||||||||||
| 63 | createAlt createContainer createStructure | ||||||||||||||||||||
| 64 | )) { | ||||||||||||||||||||
| 65 | 43668 | ▶ | *$method = sub { shift; $default_factory->$method(@_) } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 66 | 108 | } | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 9 | 1; | |||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||