App/financeta/utils.pm

filter: Statementstmt 54.8% 34 / 62 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.1% 11 / 18 Podpod 25.0% 1 / 4 totaltotal 46.4% 46 / 99 CC 8 SCAR 25.1
CC
8
Cov
45%
get_file_path
42.0
__ANON__
12.0
log_filter
2.0
CRAP 12.4
« App/financeta/data/yahoo.pm ↑ Summary auto/share/dist/App-financeta/testpdl.pl »
1 package App::financeta::utils;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Log::Any '$log', filter => \&log_filter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::ShareDir 'dist_file';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Spec::Functions qw(rel2abs catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = '0.16';
14 3 $VERSION = eval $VERSION;
15 3 our @EXPORT_OK = (
16 qw(dumper log_filter get_icon_path get_file_path)
17 );
18  
19 1 ▶sub dumper {
Subroutine dumper: called CC=1 SCAR=0.0
Pod documented
20 1 Data::Dumper->new([@_])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
21 }
22  
23 0 ▶sub log_filter {
Subroutine log_filter: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my ($c, $l) = (shift, shift);
25 ## copied from Log::Any::Adapter::Util
26 0 my %levels = (
27 0 => 'EMERGENCY',
28 1 => 'ALERT',
29 2 => 'CRITICAL',
30 3 => 'ERROR',
31 4 => 'WARNING',
32 5 => 'NOTICE',
33 6 => 'INFO',
34 7 => 'DEBUG',
35 8 => 'TRACE',
36 );
37 0 return "[$levels{$l}]($c) @_";
38 }
39  
40 0 ▶sub get_icon_path {
Subroutine get_icon_path: not called CC=1 SCAR=6.9
Pod undocumented
41 0 return get_file_path('chart-line-solid.png', @_);
42 }
43  
44 0 ▶sub get_file_path {
Subroutine get_file_path: not called CC=6 SCAR=37.4
Pod undocumented
45 0 my ($filename, @args) = @_;
46 0 ▶ return unless defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 0 0
47 0 my $file_path;
48 0 my $distname = 'App-financeta';
49 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 $file_path = dist_file($distname, $filename);
51 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 $log->warn("Failed to find $filename. Error: $_");
53 0 $file_path = undef;
54 0 };
55 0 ▶ unless ($file_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file_path) 0 0 0
56 0 my $dist_share_path = rel2abs(catfile(getcwd, 'share'));
57 0 ▶ try {
Subroutine __ANON__: not called CC=3 SCAR=24.8
58 0 $log->debug("$filename backup dist-share path: $dist_share_path");
59 ## find all packages and search for all of them
60 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
61 0 foreach (@args) {
62 0 $File::ShareDir::DIST_SHARE{$_} = $dist_share_path;
63 }
64 }
65 0 $File::ShareDir::DIST_SHARE{$distname} = $dist_share_path;
66 0 $file_path = dist_file($distname, $filename);
67 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 $log->warn("Failed to find $filename in $dist_share_path. Error: $_");
69 0 $file_path = undef;
70 0 };
71 };
72 0 ▶ $log->debug("$filename path: $file_path") if defined $file_path;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file_path 0 0 0
73 0 ▶ if (defined $file_path and -e $file_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file_path and -e $file_path) { } 0 0 0
Condition0%0/3
defined $file_path and -e $file_path
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file_path and -e $file_path
defined $file_path -e $file_path
Truth table0%0/3
A and B
A= defined $file_pathB= -e $file_path
ABresult
0X0
100
111
74 0 return $file_path;
75 } else {
76 0 $log->warn("No $filename found");
77 0 return undef;
78 }
79 }
80  
81 3 1;
82 __END__
« App/financeta/data/yahoo.pm ↑ Summary auto/share/dist/App-financeta/testpdl.pl »