lib/AutoCode/ModuleFactory.pm

filter: Statementstmt 100% 89 / 89 Branchbran 78.5% 11 / 14 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 1 totaltotal 95.3% 122 / 128 CC 12 SCAR 10.0
CC
12
Cov
96%
make_module
5.0
_initialize
4.0
__ANON__
4.0
CRAP 2.7
« lib/AutoCode/ModuleLoader.pm ↑ Summary lib/AutoCode/Plurality.pm »
1 package AutoCode::ModuleFactory;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use AutoCode::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 our @ISA=qw(AutoCode::Root);
5 5 ▶use AutoCode::ModuleModel;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # use AutoCode::Initializer;
7 5 ▶use AutoCode::Plurality;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use AutoCode::AccessorMaker('$'=>[qw(schema package_prefix)]);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 ▶use AutoCode::Compare;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 ▶sub _initialize {
Subroutine _initialize: called CC=4 SCAR=14.0
14 5 my ($self, @args)=@_;
15  
16 5 my ($schema, $package_prefix)=
17 $self->_rearrange([qw(SCHEMA PACKAGE_PREFIX)], @args);
18 5 ▶ defined $schema or $self->throw("NO Schema set");
Branch: 1 branch
BranchTrueFalseTotal
defined $schema or $self->throw("NO Schema set") 5 0 5
19 5 $self->schema($schema);
20 5 ▶ $package_prefix ||= $schema->package_prefix;
Condition66%2/3
$package_prefix ||= $schema->package_prefix
l!l&&r!l&&!r
032
MC/DC50%1/2
$package_prefix ||= $schema->package_prefix
$package_prefix $schema->package_prefix
Truth table66%2/3
A ||= B
A= $package_prefixB= $schema->package_prefix
ABresult
1X1
011
000
21 5 ▶ $package_prefix ||= 'AutoCode';
Condition100%2/2
$package_prefix ||= "AutoCode"
l!l
32
MC/DC100%1/1
$package_prefix ||= "AutoCode"
$package_prefix
Truth table100%2/2
A
A= $package_prefix
Aresult
11
00
22 5 $self->package_prefix($package_prefix);
23 }
24  
25 # *make_virtual_module = \&make_module;
26  
27 18 ▶sub make_module {
Subroutine make_module: called CC=5 SCAR=16.1
Pod undocumented
28 18 my ($self, $type, $isa) =@_;
29 ## this is added due to AutoSQL::ModuleFactory
30 18 ▶ $isa='AutoCode::Root' unless defined $isa;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $isa 18 0 18
31 18 my $schema=$self->schema;
32 18 my $package_prefix=$self->package_prefix;
33 18 my $vp = $self->_get_virtual_package($type);
34
35 18 my $model = $schema->get_module_model($type);
36 # generate its parents modules if any.
37 18 my @isa=$model->get_isas($type);
38 18 ▶ if(@isa){
Branch: 1 branch
BranchTrueFalseTotal
if (@isa) 10 8 18
39 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 10 foreach(@isa){
41 10 push @{"$vp\::ISA"}, $self->make_module($_);
42 }
43 }
44  
45 # virtual package is with the consideration of schema name and type.
46 18 my $vp = $self->_get_virtual_package($type);
47 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 18 ▶ push @{"$vp\::ISA"}, $isa unless grep /^$isa$/, @{"$vp\::ISA"};
Branch: 1 branch
BranchTrueFalseTotal
unless grep /^$isa$/, @{"${vp}::ISA";} 14 4 18
49 # $self->_add_scalar_accessor(@scalar_accessors);
50 18 $self->debug("making $type in $vp");
51
52 # map {*{"$vp\::$_"} = \&{__PACKAGE__."::$_"}} @scalar_accessors;
53 18 map {AutoCode::AccessorMaker->make_scalar_accessor($_, $vp);}
54 $model->get_scalar_attributes;
55 18 map {AutoCode::AccessorMaker->make_array_accessor(
56 [$_, $schema->get_plural($_)], $vp);
57 } $model->get_array_attributes;
58 18 $self->_make_initialize($type, $vp);
59 18 $self->_make_friends($type, $vp);
60 18 return $vp;
61 }
62  
63  
64 18 ▶sub _make_initialize {
Subroutine _make_initialize: called CC=1 SCAR=0.0
65 18 my ($self, $type, $pkg)=@_;
66 18 my $schema = $self->schema;
67 18 my $package_prefix=$self->package_prefix;
68 18 my $model = $self->schema->get_module_model($type);
69 18 my $pkg=$self->_get_virtual_package($type);
70 18 AutoCode::AccessorMaker->make_initialize_by_model($model, $pkg);
71 }
72  
73 18 ▶sub _make_friends {
Subroutine _make_friends: called CC=2 SCAR=6.9
74 18 my ($self, $type, $pkg)=@_;
75 18 my $schema = $self->schema;
76 18 my @friends=$schema->find_friends($type);
77 18 foreach my $friend_nickname (@friends){
78 # print STDERR "$_ as a friend\n\L$_\n";
79 8 AutoCode::AccessorMaker->make_hash_accessor("$friend_nickname", $pkg);
80 8 $self->_make_friend_add($type, $friend_nickname, $pkg);
81
82 }
83 }
84  
85 8 ▶sub _make_friend_add {
Subroutine _make_friend_add: called CC=1 SCAR=0.0
86 8 my ($self, $my_nickname, $friend_nickname, $pkg)=@_;
87
88 8 my $glob="$pkg\::get_". AutoCode::Plurality->query_plural($friend_nickname);
89 8 $glob="$pkg\::add_$friend_nickname";
90 8 my $slot="$pkg\::$friend_nickname\_\%";
91 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
92 2 ▶ *$glob=sub{
Subroutine __ANON__: called CC=4 SCAR=13.9
93 2 my ($self, $friend, $extra)=@_;
94 2 ▶ return unless defined $friend;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $friend 0 2 2
95 2 ▶ $self->{$slot}={} unless exists $self->{$slot};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$slot} 1 1 2
96 2 $self->{$slot}->{$friend}=$extra;
97 # add itself to its friend as friend.
98 2 my $method="get_". AutoCode::Plurality->query_plural($my_nickname);
99 2 my %hash=$friend->$method();
100 2 ▶ unless(grep {AutoCode::Compare->equal($_, "$self")} keys %hash){
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {"AutoCode::Compare"->equal($_, "$self");} keys %hash) 1 1 2
101 1 my $my_method="add_$my_nickname";
102 1 $friend->$my_method($self, $extra);
103 }
104 8 };
105 }
106  
107 54 ▶sub _get_virtual_package {
Subroutine _get_virtual_package: called CC=1 SCAR=0.0
108 54 my ($self, $type)=@_;
109 54 my $package_prefix=$self->package_prefix;
110 54 return "$package_prefix\::Virtual::$type"; # 'virtual package'
111 }
112  
113 5 1;
« lib/AutoCode/ModuleLoader.pm ↑ Summary lib/AutoCode/Plurality.pm »