lib/Bb/Collaborate/Ultra/Util.pm

filter: Statementstmt 89.7% 35 / 39 Branchbran 72.5% 29 / 40 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 81.1% 73 / 90 CC 24 SCAR 25.4
CC
24
Cov
80%
_freeze
14.7
_thaw
14.2
BEGIN
1.0
CRAP 12.6
« lib/Bb/Collaborate/Ultra/Connection.pm ↑ Summary lib/Bb/Collaborate/Ultra/Session/Log.pm »
1 package Bb::Collaborate::Ultra::Util;
2  
3 =head1 NAME
4  
5 Bb::Collaborate::Ultra::Util - Utility functions for Collaborate Ultra
6  
7 =head1 DESCRIPTION
8  
9 For internal use only.
10  
11 =cut
12  
13 7 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
14 7 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use Date::Parse qw<str2time>;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶sub _freeze {
Subroutine _freeze: called CC=13 SCAR=26.9
17 18 my ($val, $type) = @_;
18  
19 18 for ($val) {
20  
21 18 ▶ if (!defined) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_) { } 0 18 18
22 0 warn "undefined value of type $type\n"
23 }
24 else {
25 18 my $raw_val = $_;
26  
27 18 ▶ if ($type =~ m{^Bool}ix) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type =~ /^Bool/xi) { } 3 15 18
elsif ($type =~ /^(Str|enum)/xi) { } 9 6 15
elsif ($type =~ /^Int/xi) { } 0 6 6
elsif ($type =~ /^Date/) { } 4 2 6
elsif ($type =~ /^Ref|Any|Hash/xi) { } 0 2 2
28  
29 #
30 # DBize boolean flags..
31 #
32 3 ▶ $_ = $_ ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$_ ? : 2 1 3
33 }
34 elsif ($type =~ m{^(Str|enum)}ix) {
35  
36 #
37 # low level check for taintness. Only applicable when
38 # perl program is running in taint mode
39 #
40 9 ▶ die "attempt to freeze tainted data (type $type): $_"
Branch: 1 branch
BranchTrueFalseTotal
if &Scalar::Util::tainted($_) 0 9 9
41 if Scalar::Util::tainted($_);
42 #
43 # l-r trim
44 #
45 9 ▶ $_ = $1
Branch: 1 branch
BranchTrueFalseTotal
if /^ \s* (.*?) \s* $/x 9 0 9
46 if m{^ \s* (.*?) \s* $}x;
47 9 ▶ $_ = lc if $type =~ m{^enum};
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^enum/ 2 7 9
48 }
49 elsif ($type =~ m{^Int}ix) {
50 0 $_ = $_ + 0;
51 }
52 elsif ($type =~ m{^Date}) {
53 4 my ($sec,$min,$hr,$day,$mon,$year) = gmtime $_;
54 4 $_ = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
55 $year+1900, $mon+1, $day, $hr, $min, $sec;
56 }
57 elsif ($type =~ m{^Ref|Any|Hash}ix) {
58 # pass through
59 }
60 else {
61 2 ▶ die "unable to convert $raw_val to $type\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 2 2
62 unless defined;
63 }
64 }
65 };
66  
67 18 return $val;
68 }
69  
70 #
71 # thawing of elementary data-types
72 #
73  
74 24 ▶sub _thaw {
Subroutine _thaw: called CC=12 SCAR=26.6
75 24 my ($val, $type) = @_;
76  
77 24 ▶ return $val
Branch: 1 branch
BranchTrueFalseTotal
if not defined $val or $type =~ /Ref|Array/i 2 22 24
Condition66%2/3
not defined $val or $type =~ /Ref|Array/i
l!l&&r!l&&!r
0222
MC/DC50%1/2
not defined $val or $type =~ /Ref|Array/i
not defined $val $type =~ /Ref|Array/i
Truth table66%2/3
not(A) or B
A= not defined $valB= $type =~ /Ref|Array/i
ABresult
1X1
011
000
78 if !defined $val || $type =~ m{Ref|Array}i;
79  
80 22 for ($val) {
81  
82 22 ▶ if ($type =~ m{^Bool}i) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type =~ /^Bool/i) { } 6 16 22
elsif ($type =~ /^(Str|enum)/i) { } 8 8 16
elsif ($type =~ /^Int/i) { } 0 8 8
elsif ($type =~ /^Date/) { } 8 0 8
elsif ($type =~ /^Ref|Any|Hash/xi) { } 0 0 0
83 #
84 # Perlise boolean flags..
85 #
86 6 ▶ $_ = m{^(true|1)$}i ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
/^(true|1)$/i ? : 4 2 6
87 }
88 elsif ($type =~ m{^(Str|enum)}i) {
89 #
90 # l-r trim
91 #
92 8 ▶ $_ = $1
Branch: 1 branch
BranchTrueFalseTotal
if /^ \s* (.*?) \s* $/x 8 0 8
93 if m{^ \s* (.*?) \s* $}x;
94 8 ▶ $_ = lc if $type =~ m{^enum}i;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^enum/i 2 6 8
95 }
96 elsif ($type =~ m{^Int}i) {
97 0 $_ = $_ + 0;
98 }
99 elsif ($type =~ m{^Date}) {
100 8 $_ = str2time $_;
101 }
102 elsif ($type =~ m{^Ref|Any|Hash}ix) {
103 # pass through
104 }
105 else {
106 0 die "unknown type: $type";
107 }
108 };
109  
110 22 return $val;
111 }
112  
113 7 1;
« lib/Bb/Collaborate/Ultra/Connection.pm ↑ Summary lib/Bb/Collaborate/Ultra/Session/Log.pm »