blib/lib/YATT/Lite/Site/Registry.pm

filter: Statementstmt 89.4% 34 / 38 Branchbran 75.0% 3 / 4 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 2 totaltotal 71.0% 49 / 69 CC 7 SCAR 13.4
CC
7
Cov
79%
site_for
6.4
list_sites
6.0
BEGIN
1.0
CRAP 3.8
« blib/lib/YATT/Lite/Partial/MarkAfterNew.pm ↑ Summary misc/cpan/MyBuilder.pm »
1 package YATT::Lite::Site::Registry; sub MY () {__PACKAGE__}
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings qw(FATAL all NONFATAL misc);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use parent qw(YATT::Lite::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use YATT::Lite::MFields qw/_sites default_opts/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 require File::Spec;
11 6 require File::Basename;
12  
13 6 ▶use YATT::Lite::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 #========================================
16 # Per-app-root site cache, for tools which walk over files belonging to
17 # multiple sites (yatt.genperl, language servers and so on).
18 #
19 # my $reg = YATT::Lite::Site::Registry->new(default_opts => {...});
20 # my $site = $reg->site_for($filename);
21 #
22 # Files under the same app root (the directory of app.psgi/runyatt.psgi)
23 # share one site object. Files without a factory script get a default
24 # site (Site->load_or_default) keyed by their directory.
25 #========================================
26  
27 13 ▶sub site_for {
Subroutine site_for: called CC=6 SCAR=18.6
Pod undocumented
28 13 my ($self, $fn) = @_;
29 13 ▶ defined $fn and $fn ne ''
Branch: 1 branch
BranchTrueFalseTotal
defined $fn and $fn ne "" or croak("site_for: filename is missing!") 13 0 13
Condition33%1/3
defined $fn and $fn ne ""
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $fn and $fn ne ""
defined $fn $fn ne ""
Truth table33%1/3
A and B
A= defined $fnB= $fn ne ""
ABresult
0X0
100
111
30 or croak "site_for: filename is missing!";
31 13 my $dir = File::Basename::dirname
32 (YATT::Lite::Util::normalize_fs_path(File::Spec->rel2abs($fn)));
33 13 require YATT::Lite::Factory;
34 13 my $key = do {
35 13 ▶ if (my $script = YATT::Lite::Factory->find_factory_script($dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $script = 'YATT::Lite::Factory'->find_factory_script($dir)) { } 2 11 13
36 2 File::Basename::dirname($script);
37 } else {
38 11 $dir;
39 }
40 };
41 $self->{_sites}{$key}
42 //= YATT::Lite::Site->load_or_default
43 13 ▶ (dir => $dir, %{$self->{default_opts} // +{}});
Condition60%3/5
$self->{"_sites"}{$key} //= "YATT::Lite::Site"->load_or_default("dir", $dir, %{$self->{"default_opts"} // {};})
l!l&&r!l&&!r
3100
$self->{"default_opts"} // {}
l!l
010
MC/DC0%0/2
$self->{"_sites"}{$key} //= "YATT::Lite::Site"->load_or_default("dir", $dir, %{$self->{"default_opts"} // {};})
$self->{"_sites"}{$key} "YATT::Lite::Site"->load_or_default("dir", $dir, %{$self->{"default_opts"} // {};})
MC/DC0%0/1
$self->{"default_opts"} // {}
$self->{"default_opts"}
Truth table66%2/3
A //= B
A= $self->{"_sites"}{$key}B= "YATT::Lite::Site"->load_or_default("dir", $dir, %{$self->{"default_opts"} // {};})
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->{"default_opts"}
Aresult
11
00
44 }
45  
46 0 ▶sub list_sites {
Subroutine list_sites: not called CC=2 SCAR=17.9
Pod undocumented
47 0 my ($self) = @_;
48 0 ▶ map {$self->{_sites}{$_}} sort keys %{$self->{_sites} // +{}};
Condition0%0/2
$self->{"_sites"} // {}
l!l
00
MC/DC0%0/1
$self->{"_sites"} // {}
$self->{"_sites"}
Truth table0%0/2
A
A= $self->{"_sites"}
Aresult
11
00
49 }
50  
51 6 1;
« blib/lib/YATT/Lite/Partial/MarkAfterNew.pm ↑ Summary misc/cpan/MyBuilder.pm »