blib/lib/YATT/Lite/NSBuilder.pm

filter: Statementstmt 92.4% 86 / 93 Branchbran 81.8% 18 / 22 Conditioncond 55.0% 11 / 20 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 91.3% 21 / 23 Podpod 0.0% 0 / 10 totaltotal 75.1% 136 / 181 CC 20 SCAR 13.6
CC
20
Cov
85%
buildns
9.3
init_app_ns
5.1
_before_after_new
4.6
CRAP 3.9
« blib/lib/YATT/Lite/Constants.pm ↑ Summary blib/lib/YATT/Lite/ConnectionProxy.pm »
1 package YATT::Lite::NSBuilder; sub MY () {__PACKAGE__}
2 73 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 73 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 73 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 73 ▶use YATT::Lite::Util qw(lexpand);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 73 ▶use constant DEBUG => $ENV{DEBUG_YATT_NSBUILDER} // 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{"DEBUG_YATT_NSBUILDER"} // 0
l!l
073
MC/DC0%0/1
$ENV{"DEBUG_YATT_NSBUILDER"} // 0
$ENV{"DEBUG_YATT_NSBUILDER"}
Truth table50%1/2
A
A= $ENV{"DEBUG_YATT_NSBUILDER"}
Aresult
11
00
9  
10 {
11 # bootscript が決まれば、root NS も一つに決まる、としよう。 MyYATT 、と。
12 # instpkg の系列も決まる、と。 MyYATT::INST1, 2, ... だと。
13 # XXX: INST を越えて共有される *.ytmpl/ は、 TMPL1, 2, ... と名づけたいが、...
14 # それ以下のディレクトリ名・ファイル名はそのまま pkgname に使う。
15  
16 # MyYATT::INST1::dir::dir::dir::file
17 # MyYATT::TMPL1::dir::dir::dir::file
18 73 ▶ use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 73 ▶ use YATT::Lite::Partial::MarkAfterNew -as_base;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 73 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 73 ▶ use YATT::Lite::Util qw(ckeval ckrequire set_inc symtab globref);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 73 our %SEEN_NS;
24 73 ▶ use YATT::Lite::MFields qw/app_ns _app_ns
Subroutine BEGIN: called CC=1 SCAR=0.0
25 default_app _default_app
26 auto_rename_ns
27 73 _subns/;
28 213 ▶ sub _before_after_new {
Subroutine _before_after_new: called CC=4 SCAR=15.2
29 213 (my MY $self) = @_;
30 213 $self->SUPER::_before_after_new;
31 213 ▶ if ($self->{app_ns} and $SEEN_NS{$self->{app_ns}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"app_ns"} and $YATT::Lite::NSBuilder::SEEN_NS{$self->{"app_ns"}}) 0 213 213
Condition66%2/3
$self->{"app_ns"} and $YATT::Lite::NSBuilder::SEEN_NS{$self->{"app_ns"}}
!ll&&!rl&&r
241890
MC/DC0%0/2
$self->{"app_ns"} and $YATT::Lite::NSBuilder::SEEN_NS{$self->{"app_ns"}}
$self->{"app_ns"} $YATT::Lite::NSBuilder::SEEN_NS{$self->{"app_ns"}}
Truth table66%2/3
A and B
A= $self->{"app_ns"}B= $YATT::Lite::NSBuilder::SEEN_NS{$self->{"app_ns"}}
ABresult
0X0
100
111
32 0 confess "app_ns '$self->{app_ns}' is already used!";
33 }
34 213 ▶ $self->{auto_rename_ns} //= $self->default_auto_rename_ns;
Condition33%1/3
$self->{"auto_rename_ns"} //= $self->default_auto_rename_ns
l!l&&r!l&&!r
02130
MC/DC0%0/2
$self->{"auto_rename_ns"} //= $self->default_auto_rename_ns
$self->{"auto_rename_ns"} $self->default_auto_rename_ns
Truth table33%1/3
A //= B
A= $self->{"auto_rename_ns"}B= $self->default_auto_rename_ns
ABresult
1X1
011
000
35 213 $self->init_default_app;
36 213 $self->init_app_ns;
37 }
38  
39 1 ▶ sub default_subns {'INST'}
Subroutine default_subns: called CC=1 SCAR=0.0
Pod undocumented
40 19 ▶ sub default_default_app {'YATT::Lite'}
Subroutine default_default_app: called CC=1 SCAR=0.0
Pod undocumented
41 16 ▶ sub default_app_ns {'MyYATT'}
Subroutine default_app_ns: called CC=1 SCAR=0.0
Pod undocumented
42 213 ▶ sub default_auto_rename_ns { 1 }
Subroutine default_auto_rename_ns: called CC=1 SCAR=0.0
Pod undocumented
43  
44 213 ▶ sub init_default_app {
Subroutine init_default_app: called CC=2 SCAR=7.0
Pod undocumented
45 213 (my MY $self) = @_;
46 # This usually loads YATT::Lite (or YATT::Lite::WebMVC0::DirApp)
47 $self->{_default_app}
48 213 ▶ = $self->{default_app} || $self->default_default_app;
Condition66%2/3
$self->{'default_app'} || $self->default_default_app
l!l&&r!l&&!r
12120
MC/DC0%0/2
$self->{'default_app'} || $self->default_default_app
$self->{'default_app'} $self->default_default_app
Truth table66%2/3
A || B
A= $self->{'default_app'}B= $self->default_default_app
ABresult
1X1
011
000
49 213 ckrequire($self->{_default_app});
50 }
51 213 ▶ sub init_app_ns {
Subroutine init_app_ns: called CC=5 SCAR=16.2
Pod undocumented
52 213 (my MY $self) = @_;
53 # This usually set 'MyYATT'
54 213 ▶ my $app_ns = $self->{app_ns} // $self->default_app_ns;
Condition66%2/3
$self->{"app_ns"} // $self->default_app_ns
l!l&&r!l&&!r
189240
MC/DC0%0/2
$self->{"app_ns"} // $self->default_app_ns
$self->{"app_ns"} $self->default_app_ns
Truth table66%2/3
A // B
A= $self->{"app_ns"}B= $self->default_app_ns
ABresult
1X1
011
000
55 213 ▶ if (my $count = $SEEN_NS{$app_ns}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = $YATT::Lite::NSBuilder::SEEN_NS{$app_ns}++) 2 211 213
56 2 ▶ if ($self->{auto_rename_ns}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'auto_rename_ns'}) { } 2 0 2
57 2 $app_ns .= $count+1;
58 } else {
59 0 Carp::croak "Namespace collision is detected! app_ns: $app_ns";
60 }
61 }
62 213 $self->{_app_ns} = $app_ns;
63 213 try_require($app_ns);
64  
65 213 Carp::carp("init_app_ns called") if DEBUG;
66  
67 my $site_entns = $self->{_default_app}->ensure_entns
68 213 (ref $self, $self->{_default_app}->list_entns(ref $self));
69  
70 213 my @base_entns = ($self->{_default_app}->EntNS, $site_entns);
71  
72 # print "default_app is $self->{_default_app}\n";
73 # print "base entns for $app_ns is: @base_entns\n";
74  
75 213 ▶ unless ($app_ns->isa($self->{_default_app})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app_ns->isa($self->{"_default_app"})) 212 1 213
76 212 $self->define_base_of($app_ns, $self->{_default_app});
77 }
78  
79 # Then MyYATT::EntNS is composed
80 213 $self->{_default_app}->ensure_entns($app_ns, @base_entns);
81  
82 }
83 272 ▶ sub try_require {
Subroutine try_require: called CC=3 SCAR=11.2
Pod undocumented
84 272 my ($app_ns) = @_;
85 272 (my $modfn = $app_ns) =~ s|::|/|g;
86 272 local $@;
87 272 eval qq{require $app_ns};
88 272 ▶ unless ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 207 65 272
if (do { $@ =~ /^Can't locate $modfn/ }) { } 207 0 207
89 # $app_ns.pm is loaded successfully.
90 } elsif ($@ =~ m{^Can't locate $modfn}) {
91 # $app_ns.pm can be missing.
92 } else {
93 0 die $@;
94 }
95 }
96 290 ▶ sub buildns {
Subroutine buildns: called CC=9 SCAR=22.3
Pod undocumented
97 290 (my MY $self, my ($subns, $baselist, $path)) = @_;
98 290 Carp::carp("buildns called") if DEBUG;
99 290 ▶ unless (defined $self->{_app_ns}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_app_ns"}) 0 290 290
100 0 croak "buildns is called without app_ns!";
101 }
102 # This usually creates MyYATT::INST$n and set it's ISA.
103 290 ▶ $subns ||= $self->default_subns;
Condition66%2/3
$subns ||= $self->default_subns
l!l&&r!l&&!r
28910
MC/DC0%0/2
$subns ||= $self->default_subns
$subns $self->default_subns
Truth table66%2/3
A ||= B
A= $subnsB= $self->default_subns
ABresult
1X1
011
000
104 290 ▶ my @base = map {ref $_ || $_} @$baselist;
Condition33%1/3
ref $_ || $_
l!l&&r!l&&!r
0590
MC/DC0%0/2
ref $_ || $_
ref $_ $_
Truth table33%1/3
A || B
A= ref $_B= $_
ABresult
1X1
011
000
105 290 ▶ if (@base) {
Branch: 1 branch
BranchTrueFalseTotal
if (@base) 52 238 290
106 52 try_require($_) for @base;
107 52 ▶ unless (grep {$_->isa($self->{_default_app})} @base) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->isa($self->{"_default_app"});} @base) 1 51 52
108 1 croak "None of baseclass inherits $self->{_default_app}: @base";
109 }
110 }
111 my $newns = sprintf q{%s::%s%d}, $self->{_app_ns}, $subns
112 289 , ++$self->{_subns}{$subns};
113 289 ▶ $self->define_base_of($newns, @base ? @base : $self->{_app_ns});
Branch: 1 branch
BranchTrueFalseTotal
@base ? : 51 238 289
114  
115 YATT::Lite::Util::globref_default(globref($newns, 'filename')
116 289 ▶ , sub { $path });
Subroutine __ANON__: called CC=1 SCAR=0.0
117  
118 my $entns = $self->{_default_app}->ensure_entns($newns, map {
119 296 ▶ $_->EntNS
Branch: 1 branch
BranchTrueFalseTotal
@base ? : 51 238 289
120 289 } @base ? @base : $self->{_app_ns});
121  
122 YATT::Lite::Util::globref_default(globref($entns, 'filename')
123 0 ▶ , sub { $path });
Subroutine __ANON__: not called CC=1 SCAR=1.2
124  
125 289 set_inc($newns, 1);
126 289 $newns;
127 }
128 501 ▶ sub define_base_of {
Subroutine define_base_of: called CC=1 SCAR=0.0
Pod undocumented
129 501 (my MY $self, my ($newns, @base)) = @_;
130 501 YATT::Lite::MFields->add_isa_to($newns, @base)
131 ->define_fields($newns);
132 }
133 0 ▶ sub lineinfo { shift; sprintf qq{#line %d "%s"\n}, @_}
Subroutine lineinfo: not called CC=1 SCAR=6.9
Pod undocumented
134 }
135  
136 73 1;
« blib/lib/YATT/Lite/Constants.pm ↑ Summary blib/lib/YATT/Lite/ConnectionProxy.pm »