Scaffold/Util.pm

filter: Statementstmt 34.8% 23 / 66 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 53.8% 7 / 13 Podpod 100% 2 / 2 totaltotal 29.0% 32 / 110 CC 16 SCAR 33.2
CC
16
Cov
25%
hash_delta
56.0
const
36.1
__ANON__
30.0
CRAP 27.6
« Scaffold/App.pm ↑ Summary Scaffold/HierarchicalDirty.pm »
1 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Class::Scaffold::Util;
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $Class::Scaffold::Util::VERSION = '1.102280';
8 }
9 # ABSTRACT: Exports various useful functions
10 1 ▶use Error::Hierarchy::Util 'assert_hashref';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our %EXPORT_TAGS = (util => [qw/hash_delta const/],);
13 1 our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };
14  
15 # generates the delta for two given hashrefs.
16 # returns three hashrefs containing the elements of the given hashrefs
17 # which should be
18 # 1. inserted
19 # 2. updated
20 # 3. deleted
21 0 ▶sub hash_delta {
Subroutine hash_delta: not called CC=7 SCAR=40.3
Pod documented
22 0 my ($this, $that) = @_;
23 0 my ($insert, $delete, $update);
24 0 ▶ $this = {} unless defined $this;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 0 0
25 0 ▶ $that = {} unless defined $that;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $that 0 0 0
26 0 assert_hashref $this,
27 sprintf "hash_delta: \$this isn't a hashref, it's a %s", ref $this;
28 0 assert_hashref $that,
29 sprintf "hash_delta: \$that isn't a hashref, it's a %s", ref $that;
30  
31 # get extinct keys.
32 0 for (keys %$this) {
33 0 ▶ $delete->{$_} = $this->{$_} unless exists $that->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $that->{$_} 0 0 0
34 }
35  
36 # get new keys.
37 0 for (keys %$that) {
38  
39 # and catch updated keys also.
40 0 ▶ if (exists $this->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $this->{$_}) { } 0 0 0
41 0 $update->{$_} = $that->{$_};
42 } else {
43 0 $insert->{$_} = $that->{$_};
44 }
45 }
46 0 return ($insert, $update, $delete);
47 }
48  
49 0 ▶sub const ($@) {
Subroutine const: not called CC=6 SCAR=35.9
Pod documented
50 0 my $name = shift;
51 0 my %args = @_;
52 0 my ($pkg, $filename, $line) = (caller)[ 0 .. 2 ];
53 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 0 my $every_hash_name = "${name}_HASH";
55 0 ▶ $::PTAGS && $::PTAGS->add_tag($every_hash_name, $filename, $line);
Branch: 1 branch
BranchTrueFalseTotal
$main::PTAGS and $main::PTAGS->add_tag($every_hash_name, $filename, $line) 0 0 0
56 0 ▶ *{"${pkg}::${every_hash_name}"} = sub { %args };
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 0 ▶ $::PTAGS && $::PTAGS->add_tag($name, $filename, $line);
Branch: 1 branch
BranchTrueFalseTotal
$main::PTAGS and $main::PTAGS->add_tag($name, $filename, $line) 0 0 0
58 0 ▶ *{"${pkg}::${name}"} = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
59 0 my $self = shift;
60 0 my $hash = $self->every_hash($every_hash_name);
61 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
62 0 my $key = shift;
63 $hash->{$key}
64 || $hash->{_AUTO}
65 0 ▶ || throw Error::Hierarchy::Internal::CustomMessage(
Branch: 1 branch
BranchTrueFalseTotal
$hash->{$key} or $hash->{"_AUTO"} or "Error::Hierarchy::Internal::CustomMessage"->throw("custom_message", "neither key [$key] nor [_AUTO] in $every_hash_name") 0 0 0
Condition0%0/3
$hash->{$key} or $hash->{"_AUTO"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash->{$key} or $hash->{"_AUTO"}
$hash->{$key} $hash->{"_AUTO"}
Truth table0%0/3
A or B
A= $hash->{$key}B= $hash->{"_AUTO"}
ABresult
1X1
011
000
66 custom_message =>
67 "neither key [$key] nor [_AUTO] in $every_hash_name");
68 } else {
69 0 my @val = values %$hash;
70 0 ▶ return wantarray ? @val : \@val;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
71 }
72 0 };
73  
74 # have a sub that returns how many of those items there are
75 0 my $count_name = "${name}_COUNT";
76 0 ▶ $::PTAGS && $::PTAGS->add_tag($count_name, $filename, $line);
Branch: 1 branch
BranchTrueFalseTotal
$main::PTAGS and $main::PTAGS->add_tag($count_name, $filename, $line) 0 0 0
77 0 ▶ *{"${pkg}::${count_name}"} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 my $self = shift;
79 0 scalar(@{ $self->$name });
80 0 };
81 0 ▶ while (my ($key, $value) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
82 0 ▶ $::PTAGS && $::PTAGS->add_tag($key, $filename, $line);
Branch: 1 branch
BranchTrueFalseTotal
$main::PTAGS and $main::PTAGS->add_tag($key, $filename, $line) 0 0 0
83 0 ▶ *{"${pkg}::${key}"} = sub { $value };
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 }
85 }
86 1 1;
87  
88  
89 __END__
« Scaffold/App.pm ↑ Summary Scaffold/HierarchicalDirty.pm »