Catmandu.pm

filter: Statementstmt 92.1% 105 / 114 Branchbran 60.7% 17 / 28 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 96.9% 32 / 33 Podpod 0.0% 0 / 24 totaltotal 75.6% 158 / 209 CC 17 SCAR 7.1
CC
17
Cov
85%
_import_load
6.0
default_load_path
4.2
export_to_string
3.0
CRAP 2.0
« Catmandu/Fix/retain.pm ↑ Summary Catmandu/Fix/parse_text.pm »
1 package Catmandu;
2  
3 154 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 154 our $VERSION = '1.2025';
6  
7 154 ▶use Catmandu::Env;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 154 ▶use Catmandu::Util qw(:is);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 154 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 154 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 154 ▶use Sub::Exporter::Util qw(curry_method);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 154 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 exports => [
14 config => curry_method,
15 log => curry_method,
16 store => curry_method,
17 fixer => curry_method,
18 importer => curry_method,
19 exporter => curry_method,
20 validator => curry_method,
21 export => curry_method,
22 export_to_string => curry_method,
23 import_from_string => curry_method
24 ],
25 collectors => {'-load' => \'_import_load', ':load' => \'_import_load',},
26 154 };
27  
28 0 ▶sub _import_load {
Subroutine _import_load: not called CC=2 SCAR=17.9
29 0 my ($self, $value, $data) = @_;
30 0 ▶ if (is_array_ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_array_ref($value)) { } 0 0 0
31 0 $self->load(@$value);
32 }
33 else {
34 0 $self->load;
35 }
36 0 1;
37 }
38  
39 227 ▶sub _env {
Subroutine _env: called CC=3 SCAR=11.0
40 227 my ($class, $env) = @_;
41 227 state $loaded_env;
42 227 ▶ $loaded_env = $env if defined $env;
Branch: 1 branch
BranchTrueFalseTotal
if defined $env 50 177 227
43 227 ▶ $loaded_env
Condition66%2/3
$loaded_env ||= "Catmandu::Env"->new("load_paths", $class->default_load_path)
l!l&&r!l&&!r
212150
MC/DC0%0/2
$loaded_env ||= "Catmandu::Env"->new("load_paths", $class->default_load_path)
$loaded_env "Catmandu::Env"->new("load_paths", $class->default_load_path)
Truth table66%2/3
A ||= B
A= $loaded_envB= "Catmandu::Env"->new("load_paths", $class->default_load_path)
ABresult
1X1
011
000
44 ||= Catmandu::Env->new(load_paths => $class->default_load_path);
45 }
46  
47 12 ▶sub log {$_[0]->_env->log}
Subroutine log: called CC=1 SCAR=0.0
Pod undocumented
48  
49 69 ▶sub default_load_path { # TODO move to Catmandu::Env
Subroutine default_load_path: called CC=4 SCAR=14.3
Pod undocumented
50 69 my ($class, $path) = @_;
51 69 state $default_path;
52 69 ▶ $default_path = $path if defined $path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $path 2 67 69
53 69 ▶ $default_path //= do {
Condition66%2/3
$default_path //= do { my $script = "File::Spec"->rel2abs($0); () = "File::Spec"->splitpath($script); my(@dirs) = grep(length($_), "File::Spec"->splitdir($script_path)); if ($dirs[-1] eq "bin") { pop @dirs; "File::Spec"->catdir("File::Spec"->rootdir, @dirs); } else { $script_path; } }
l!l&&r!l&&!r
40290
MC/DC0%0/2
$default_path //= do { my $script = "File::Spec"->rel2abs($0); () = "File::Spec"->splitpath($script); my(@dirs) = grep(length($_), "File::Spec"->splitdir($script_path)); if ($dirs[-1] eq "bin") { pop @dirs; "File::Spec"->catdir("File::Spec"->rootdir, @dirs); } else { $script_path; } }
$default_path do { my $script = "File::Spec"->rel2abs($0); () = "File::Spec"->splitpath($script); my(@dirs) = grep(length($_), "File::Spec"->splitdir($script_path)); if ($dirs[-1] eq "bin") { pop @dirs; "File::Spec"->catdir("File::Spec"->rootdir, @dirs); } else { $script_path; } }
Truth table66%2/3
A //= B
A= $default_pathB= do { my $script = "File::Spec"->rel2abs($0); () = "File::Spec"->splitpath($script); my(@dirs) = grep(length($_), "File::Spec"->splitdir($script_path)); if ($dirs[-1] eq "bin") { pop @dirs; "File::Spec"->catdir("File::Spec"->rootdir, @dirs); } else { $script_path; } }
ABresult
1X1
011
000
54 29 my $script = File::Spec->rel2abs($0);
55 29 my ($script_vol, $script_path, $script_name)
56 = File::Spec->splitpath($script);
57 29 my @dirs = grep length, File::Spec->splitdir($script_path);
58 29 ▶ if ($dirs[-1] eq 'bin') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs[-1] eq 'bin') { } 0 29 29
59 0 pop @dirs;
60 0 File::Spec->catdir(File::Spec->rootdir, @dirs);
61 }
62 else {
63 29 $script_path;
64 }
65 };
66 }
67  
68 49 ▶sub load {
Subroutine load: called CC=2 SCAR=7.0
Pod undocumented
69 49 my $class = shift;
70 49 ▶ my $paths = [@_ ? @_ : $class->default_load_path];
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 49 49
71 49 my $env = Catmandu::Env->new(load_paths => $paths);
72 49 $class->_env($env);
73 49 $class;
74 }
75  
76 5 ▶sub roots {
Subroutine roots: called CC=1 SCAR=0.0
Pod undocumented
77 5 $_[0]->_env->roots;
78 }
79  
80 1 ▶sub root {
Subroutine root: called CC=1 SCAR=0.0
Pod undocumented
81 1 $_[0]->_env->root;
82 }
83  
84 22 ▶sub config {
Subroutine config: called CC=2 SCAR=6.9
Pod undocumented
85 22 my ($class, $config) = @_;
86 22 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 1 21 22
87 1 my $env = Catmandu::Env->new(load_paths => $class->_env->load_paths);
88 1 $env->_set_config($config);
89 1 $class->_env($env);
90 }
91 22 $class->_env->config;
92 }
93  
94 1 ▶sub default_store {$_[0]->_env->default_store}
Subroutine default_store: called CC=1 SCAR=0.0
Pod undocumented
95  
96 27 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod undocumented
97 27 my $class = shift;
98 27 $class->_env->store(@_);
99 }
100  
101 1 ▶sub default_fixer {$_[0]->_env->default_fixer}
Subroutine default_fixer: called CC=1 SCAR=0.0
Pod undocumented
102  
103 10 ▶sub fixer {
Subroutine fixer: called CC=1 SCAR=0.0
Pod undocumented
104 10 my $class = shift;
105 10 $class->_env->fixer(@_);
106 }
107  
108 1 ▶sub default_importer {$_[0]->_env->default_importer}
Subroutine default_importer: called CC=1 SCAR=0.0
Pod undocumented
109  
110 1 ▶sub default_importer_package {$_[0]->_env->default_importer_package}
Subroutine default_importer_package: called CC=1 SCAR=0.0
Pod undocumented
111  
112 33 ▶sub importer {
Subroutine importer: called CC=1 SCAR=0.0
Pod undocumented
113 33 my $class = shift;
114 33 $class->_env->importer(@_);
115 }
116  
117 1 ▶sub default_exporter {$_[0]->_env->default_exporter}
Subroutine default_exporter: called CC=1 SCAR=0.0
Pod undocumented
118  
119 1 ▶sub default_exporter_package {$_[0]->_env->default_exporter_package}
Subroutine default_exporter_package: called CC=1 SCAR=0.0
Pod undocumented
120  
121 45 ▶sub exporter {
Subroutine exporter: called CC=1 SCAR=0.0
Pod undocumented
122 45 my $class = shift;
123 45 $class->_env->exporter(@_);
124 }
125  
126 1 ▶sub validator {
Subroutine validator: called CC=1 SCAR=0.0
Pod undocumented
127 1 my $class = shift;
128 1 $class->_env->validator(@_);
129 }
130  
131 1 ▶sub export {
Subroutine export: called CC=2 SCAR=7.0
Pod undocumented
132 1 my $class = shift;
133 1 my $data = shift;
134 1 my $exporter = $class->_env->exporter(@_);
135 1 ▶ is_hash_ref($data) ? $exporter->add($data) : $exporter->add_many($data);
Branch: 1 branch
BranchTrueFalseTotal
is_hash_ref($data) ? : 1 0 1
136 1 $exporter->commit;
137 1 return;
138 }
139  
140 7 ▶sub export_to_string {
Subroutine export_to_string: called CC=3 SCAR=11.1
Pod undocumented
141 7 my $class = shift;
142 7 my $data = shift;
143 7 my $name = shift;
144 0 ▶ my %opts = ref $_[0] ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 7 7
145 7 my $str = "";
146 7 my $exporter = $class->_env->exporter($name, %opts, file => \$str);
147 7 ▶ is_hash_ref($data) ? $exporter->add($data) : $exporter->add_many($data);
Branch: 1 branch
BranchTrueFalseTotal
is_hash_ref($data) ? : 4 3 7
148 7 $exporter->commit;
149 7 $str;
150 }
151  
152 6 ▶sub import_from_string {
Subroutine import_from_string: called CC=2 SCAR=7.2
Pod undocumented
153 6 my $class = shift;
154 6 my $str = shift;
155 6 my $name = shift;
156 0 ▶ my %opts = ref $_[0] ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 6 6
157 6 $class->_env->importer($name, %opts, file => \$str)->to_array();
158 }
159  
160 1 ▶sub define_importer {
Subroutine define_importer: called CC=2 SCAR=7.0
Pod undocumented
161 1 my $class = shift;
162 1 my $name = shift;
163 1 my $package = shift;
164 1 ▶ my $options = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
165 1 $class->config->{importer}{$name}
166 = {package => $package, options => $options};
167 }
168  
169 1 ▶sub define_exporter {
Subroutine define_exporter: called CC=2 SCAR=7.0
Pod undocumented
170 1 my $class = shift;
171 1 my $name = shift;
172 1 my $package = shift;
173 1 ▶ my $options = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
174 1 $class->config->{exporter}{$name}
175 = {package => $package, options => $options};
176 }
177  
178 1 ▶sub define_store {
Subroutine define_store: called CC=2 SCAR=7.0
Pod undocumented
179 1 my $class = shift;
180 1 my $name = shift;
181 1 my $package = shift;
182 1 ▶ my $options = ref $_[0] ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1 1
183 1 $class->config->{store}{$name}
184 = {package => $package, options => $options};
185 }
186  
187 1 ▶sub define_fixer {
Subroutine define_fixer: called CC=2 SCAR=7.0
Pod undocumented
188 1 my $class = shift;
189 1 my $name = shift;
190 1 ▶ my $fixes = ref $_[0] ? $_[0] : [@_];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 0 1
191 1 $class->config->{fixer}{$name} = $fixes;
192 }
193  
194 154 1;
195  
196 __END__
« Catmandu/Fix/retain.pm ↑ Summary Catmandu/Fix/parse_text.pm »