| 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
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $that = {} unless defined $that; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | 0 | my $key = shift; | |||||||||||||||||||||||||||
| 63 | $hash->{$key} | ||||||||||||||||||||||||||||
| 64 | || $hash->{_AUTO} | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | || throw Error::Hierarchy::Internal::CustomMessage( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$hash->{$key} or $hash->{"_AUTO"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $::PTAGS && $::PTAGS->add_tag($key, $filename, $line); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | *{"${pkg}::${key}"} = sub { $value }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 1 | 1; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||