VCI/Util.pm

filter: Statementstmt 56.9% 33 / 58 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.1% 8 / 19 Podpod 100% 2 / 2 totaltotal 43.8% 43 / 98 CC 9 SCAR 20.4
CC
9
Cov
44%
taint_fail
30.0
detaint
6.0
__ANON__
6.0
CRAP 7.7
« VCI/VCS/Hg/Repository.pm ↑ Summary VCI/VCS/Bzr/History.pm »
1 package VCI::Util;
2 10 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 10 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use DateTime::Format::DateParse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Path::Abstract::Underload;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 our @ISA = qw(Exporter);
12 10 our @EXPORT_OK = qw(taint_fail detaint CLASS_METHODS);
13  
14 # A list of _class methods from VCI.pm that we delegate to other classes.
15 10 ▶use constant CLASS_METHODS => qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
16 commit_class
17 diff_class
18 directory_class
19 file_class
20 history_class
21 project_class
22 repository_class
23 10 );
24
25 ###############
26 # Subroutines #
27 ###############
28  
29 0 ▶sub taint_fail {
Subroutine taint_fail: not called CC=5 SCAR=34.0
Pod documented
30 0 my ($msg) = @_;
31
32 # Carp just fails utterly to get our messages right, no matter if we
33 # try @CARP_NOT, %Carp::CarpInternals, or $Carp::CarpLevel. So I just
34 # did this manually myself, to at least give somebody the idea of
35 # where their error is.
36 0 my $level = 1;
37 0 ▶ while (caller($level) =~ /^VCI::(?:Abstract|VCS)::/
Branch: 1 branch
BranchTrueFalseTotal
if (&CORE::GLOBAL::caller($level) =~ /^VCI::(?:Abstract|VCS)::/ or &CORE::GLOBAL::caller($level) =~ /^Moose::/) 0 0 0
Condition0%0/3
&CORE::GLOBAL::caller($level) =~ /^VCI::(?:Abstract|VCS)::/ or &CORE::GLOBAL::caller($level) =~ /^Moose::/
l!l&&r!l&&!r
000
MC/DC0%0/2
&CORE::GLOBAL::caller($level) =~ /^VCI::(?:Abstract|VCS)::/ or &CORE::GLOBAL::caller($level) =~ /^Moose::/
&CORE::GLOBAL::caller($level) =~ /^VCI::(?:Abstract|VCS)::/ &CORE::GLOBAL::caller($level) =~ /^Moose::/
Truth table0%0/3
A or B
A= &CORE::GLOBAL::caller($level) =~ /^VCI::(?:Abstract|VCS)::/B= &CORE::GLOBAL::caller($level) =~ /^Moose::/
ABresult
1X1
011
000
38 0 || caller($level) =~ /^Moose::/ ) { $level++; }
39
40 0 my @info = caller($level);
41 0 $msg .= " at $info[1] line $info[2].\n";
42 0 ▶ if (${^TAINT} == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (${^TAINT} == 1) { } 0 0 0
elsif (${^TAINT} == -1) { } 0 0 0
43 0 die($msg);
44 }
45 elsif (${^TAINT} == -1) {
46 0 warn($msg);
47 }
48 }
49  
50 0 ▶sub detaint {
Subroutine detaint: not called CC=2 SCAR=17.9
Pod documented
51 0 ▶ return if !defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
52 0 $_[0] =~ /^(.*)$/s;
53 0 $_[0] = $1;
54 }
55  
56 ################
57 # Object Types #
58 ################
59  
60 subtype 'VCI::Type::DateTime'
61 => as 'Object'
62 0 ▶ => where { $_->isa('DateTime') };
Subroutine __ANON__: not called CC=1 SCAR=1.2
63  
64 coerce 'VCI::Type::DateTime'
65 => from 'Num'
66 0 ▶ => via { DateTime->from_epoch(epoch => $_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
67 => from 'Str'
68 0 ▶ => via {
Subroutine __ANON__: not called CC=2 SCAR=17.9
69 0 my $result = DateTime::Format::DateParse->parse_datetime($_);
70 0 ▶ if (!defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
71 0 confess("Date::Parse failed to parse '$_' into a DateTime");
72 }
73 0 return $result;
74 10 };
75  
76 10 subtype 'VCI::Type::IntBool'
77 => as 'Int';
78 coerce 'VCI::Type::IntBool'
79 => from 'Undef'
80 0 ▶ => via { 0 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 => from 'Str'
82 0 ▶ => via { $_ ? 1 : 0 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 0 0 0
83  
84 subtype 'VCI::Type::Path'
85 => as 'Object',
86 0 ▶ => where { $_->isa('Path::Abstract::Underload') && $_->stringify !~ m{/\s*$}o };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_->isa("Path::Abstract::Underload") and not $_->stringify =~ m[/\s*$]o 0 0 0
87  
88 coerce 'VCI::Type::Path'
89 => from 'Str'
90 0 ▶ => via {
Subroutine __ANON__: not called CC=1 SCAR=6.9
91 0 $_ =~ s{/\s*$}{}o;
92 0 Path::Abstract::Underload->new($_)->to_branch;
93 }
94 => from 'ArrayRef'
95 # XXX This may not deal with trailing slashes properly.
96 0 ▶ => via { Path::Abstract::Underload->new(@$_)->to_branch; }
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 => from 'Object'
98 0 ▶ => via { $_->to_branch };
Subroutine __ANON__: not called CC=1 SCAR=1.2
99  
100  
101 10 1;
102  
103 __END__
« VCI/VCS/Hg/Repository.pm ↑ Summary VCI/VCS/Bzr/History.pm »