| 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 | sub _freeze { | ||||||||||||||||||||||||||||
| 17 | 18 | ▶ | my ($val, $type) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_freeze: called CC=13 SCAR=26.9
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 18 | for ($val) { | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 18 | ▶ | if (!defined) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||
| 30 | # DBize boolean flags.. | ||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||
| 32 | 3 | ▶ | $_ = $_ ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 41 | if Scalar::Util::tainted($_); | ||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||
| 43 | # l-r trim | ||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | 9 | ▶ | $_ = $1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | if m{^ \s* (.*?) \s* $}x; | ||||||||||||||||||||||||||||
| 47 | 9 | ▶ | $_ = lc if $type =~ m{^enum}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | unless defined; | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 18 | return $val; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||
| 71 | # thawing of elementary data-types | ||||||||||||||||||||||||||||
| 72 | # | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub _thaw { | ||||||||||||||||||||||||||||
| 75 | 24 | ▶ | my ($val, $type) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_thaw: called CC=12 SCAR=26.6
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 24 | ▶ | return $val | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $val or $type =~ /Ref|Array/i
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||
| 84 | # Perlise boolean flags.. | ||||||||||||||||||||||||||||
| 85 | # | ||||||||||||||||||||||||||||
| 86 | 6 | ▶ | $_ = m{^(true|1)$}i ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | elsif ($type =~ m{^(Str|enum)}i) { | ||||||||||||||||||||||||||||
| 89 | # | ||||||||||||||||||||||||||||
| 90 | # l-r trim | ||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||
| 92 | 8 | ▶ | $_ = $1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | if m{^ \s* (.*?) \s* $}x; | ||||||||||||||||||||||||||||
| 94 | 8 | ▶ | $_ = lc if $type =~ m{^enum}i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||