Valiant/Util.pm

filter: Statementstmt 86.8% 33 / 38 Branchbran 16.6% 2 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 91.6% 11 / 12 Podpod 66.6% 4 / 6 totaltotal 70.4% 50 / 71 CC 9 SCAR 20.7
CC
9
Cov
67%
debug
25.3
DEBUG_FLAG
6.0
process_template
2.0
CRAP 8.0
« Valiant/Filter/Flatten.pm ↑ Summary Valiant/JSON/JSONBuilder.pm »
1 package Valiant::Util;
2  
3 56 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 56 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 56 ▶use Module::Runtime;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 56 ▶use Moo::_Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 56 our @DEFAULT_EXPORTS = qw( throw_exception debug DEBUG_FLAG process_template );
10  
11 315 ▶sub default_exports { @DEFAULT_EXPORTS }
Subroutine default_exports: called CC=1 SCAR=0.0
Pod undocumented
12  
13 315 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
14 315 my $class = shift;
15 315 my $target = caller;
16 315 my @exports = $class->default_exports;
17  
18 315 foreach my $exported_method (@exports) {
19 1260 ▶ my $sub = sub { $class->$exported_method($target, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine throw_exception: called CC=1 SCAR=0.0
Pod documented
20 1260 Moo::_Utils::_install_tracked($target, $exported_method, $sub);
21 }
22 }
23  
24 2 ▶sub throw_exception {
Subroutine throw_exception: called CC=1 SCAR=0.0
Pod documented
25 2 my ($class, $target, $class_name, @args) = @_;
26 2 my $namespace = "Valiant::Util::Exception::$class_name";
27 2 my $exception = Module::Runtime::use_module($namespace)->new(@args);
28 2 die $exception->as_string;
29 }
30  
31 0 ▶sub DEBUG_FLAG { $ENV{VALIANT_DEBUG} ? 1:0 }
Subroutine DEBUG_FLAG: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'VALIANT_DEBUG'} ? : 0 0 0
32  
33 12166 ▶sub debug {
Subroutine debug: called CC=6 SCAR=32.3
Pod documented
34 12166 my ($class, $target, $target_level, @args) = @_;
35 12166 ▶ return unless exists $ENV{VALIANT_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ENV{"VALIANT_DEBUG"} 12166 0 12166
36 0 my ($level, $package_pattern) = split(',', $ENV{VALIANT_DEBUG});
37 0 ▶ if($package_pattern) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_pattern) 0 0 0
38 0 ▶ return unless $target eq ($package_pattern||'');
Branch: 1 branch
BranchTrueFalseTotal
unless $target eq ($package_pattern || "") 0 0 0
Condition0%0/2
$package_pattern || ''
l!l
00
MC/DC0%0/1
$package_pattern || ''
$package_pattern
Truth table0%0/2
A
A= $package_pattern
Aresult
11
00
39 }
40 0 ▶ warn "$target: @args\n" if $level >= $target_level;
Branch: 1 branch
BranchTrueFalseTotal
if $level >= $target_level 0 0 0
41 }
42  
43 1 ▶sub process_template {
Subroutine process_template: called CC=2 SCAR=7.0
Pod documented
44 1 my ($class, $target, $template, %values) = @_;
45 1 ▶ $template =~ s/\{\{([^}]+)\}\}/ defined($values{$1}) ? $values{$1}: '' /gex;
Branch: 1 branch
BranchTrueFalseTotal
defined $values{$1} ? : 2 0 2
46 1 return $template;
47 }
48  
49 56 1;
50  
51 =head1 NAME
52  
53 Valiant::Util - Importable utility methods;
54  
55 =head1 SYNOPSIS
56  
57 use Valiant::Util 'throw_exception';
58  
59 throw_exception 'MissingMethod' => (object=>$self, method=>'if');
60  
61 =head1 DESCRIPTION
62  
63 Just a place to stick various utility functions that are cross cutting concerns.
64  
65 =head1 SUBROUTINES
66  
67 This package has the following subroutines for EXPORT
68  
69 =head2 debug
70  
71 debug $level, 'message';
72  
73 Send debuggin info to STDERR if $level is greater or equal to the current log level
74 (default log level is '0' or 'no logging').
75  
76 =head2 throw_exception
77  
78 throw_exception 'MissingMethod' => (object=>$self, method=>'if');
79  
80 Used to encapsulate exception types. Maybe someday we can do continuations instead :)
81  
82 =head2 process_template
83  
84 process a very simple string template
85  
86 =head1 SEE ALSO
87
88 L<Valiant>
89  
90 =head1 AUTHOR
91
92 See L<Valiant>
93  
94 =head1 COPYRIGHT & LICENSE
95
96 See L<Valiant>
97  
98 =cut
« Valiant/Filter/Flatten.pm ↑ Summary Valiant/JSON/JSONBuilder.pm »