Data/Perl/Collection/Hash/MooseLike.pm

filter: Statementstmt 100% 17 / 17 Branchbran 100% 4 / 4 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 85.2% 29 / 34 CC 5 SCAR 13.0
CC
5
Cov
89%
__ANON__
5.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.7
« MooX/HandlesVia.pm ↑ Summary Data/Perl/Collection/Array/MooseLike.pm »
1 package Data::Perl::Collection::Hash::MooseLike;
2 6 $Data::Perl::Collection::Hash::MooseLike::VERSION = '0.001009';
3 # ABSTRACT: Collection::Hash subclass that simulates Moose's native traits.
4  
5 6 ▶use strictures 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Class::Method::Modifiers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 with 'Data::Perl::Role::Collection::Hash';
11  
12 48 ▶around 'set', 'get', 'delete' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
13 48 my $orig = shift;
14 48 my @res = $orig->(@_);
15  
16 # support both class instance method invocation style
17 48 ▶ @res = blessed($res[0])
Branch: 1 branch
BranchTrueFalseTotal
&blessed($res[0]) && ($res[0]->isa('Data::Perl::Collection::Hash') || $res[0]->isa('Data::Perl::Collection::Array')) ? : 2 46 48
Condition50%3/6
&blessed($res[0]) and $res[0]->isa("Data::Perl::Collection::Hash") || $res[0]->isa("Data::Perl::Collection::Array")
!ll&&!rl&&r
4602
$res[0]->isa("Data::Perl::Collection::Hash") or $res[0]->isa("Data::Perl::Collection::Array")
l!l&&r!l&&!r
020
MC/DC33%1/3
&blessed($res[0]) and $res[0]->isa("Data::Perl::Collection::Hash") || $res[0]->isa("Data::Perl::Collection::Array")
&blessed($res[0]) $res[0]->isa("Data::Perl::Collection::Hash") $res[0]->isa("Data::Perl::Collection::Array")
Truth table50%2/4
A and B or C
A= &blessed($res[0])B= $res[0]->isa("Data::Perl::Collection::Hash")C= $res[0]->isa("Data::Perl::Collection::Array")
ABCresult
0XX0
1000
11X1
1011
18 && ($res[0]->isa('Data::Perl::Collection::Hash')
19 || $res[0]->isa('Data::Perl::Collection::Array')) ? $res[0]->flatten : @res;
20  
21 48 ▶ wantarray ? @res : $res[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 36 48
22 6 };
23  
24 6 1;
25  
26 =pod
27  
28 =encoding UTF-8
29  
30 =head1 NAME
31  
32 Data::Perl::Collection::Hash::MooseLike - Collection::Hash subclass that simulates Moose's native traits.
33  
34 =head1 VERSION
35  
36 version 0.001009
37  
38 =head1 SYNOPSIS
39  
40 use Data::Perl::Collection::Hash::MooseLike;
41  
42 my $hash = Data::Perl::Collection::Hash::MooseLike->new(a => 1, b => 2);
43  
44 $hash->values; # (1, 2)
45  
46 $hash->set('foo', 'bar'); # (a => 1, b => 2, foo => 'bar')
47  
48 =head1 DESCRIPTION
49  
50 This class provides a wrapper and methods for interacting with a hash. All
51 methods are written to emulate/match existing behavior that exists with Moose's
52 native traits.
53  
54 =head1 DIFFERENCES IN FUNCTIONALITY
55  
56 =over 4
57  
58 =item B<get($key, $key, ...)>
59  
60 Returns values from the hash.
61  
62 In list context it returns a list of values in the hash for the given keys. In
63 scalar context it returns the value for the last key specified.
64  
65 =item B<set($key, $value, ...)>
66  
67 Sets the elements in the hash to the given values. It returns the new values
68 set for each key, in the same order as the keys passed to the method.
69  
70 This method requires at least two arguments, and expects an even number of
71 arguments.
72  
73 =item B<delete($key, $key, ...)>
74  
75 Removes the elements with the given keys.
76  
77 In list context it returns a list of values in the hash for the deleted keys.
78 In scalar context it returns the value for the last key specified.
79  
80 =back
81  
82 =head1 SEE ALSO
83  
84 =over 4
85  
86 =item * L<Data::Perl>
87  
88 =item * L<Data::Perl::Role::Collection::Hash>
89  
90 =back
91  
92 =head1 AUTHOR
93  
94 Toby Inkster <tobyink@cpan.org>
95  
96 =head1 COPYRIGHT AND LICENSE
97  
98 This software is copyright (c) 2020 by Matthew Phillips <mattp@cpan.org>.
99  
100 This is free software; you can redistribute it and/or modify it under
101 the same terms as the Perl 5 programming language system itself.
102  
103 =cut
104  
105 __END__
« MooX/HandlesVia.pm ↑ Summary Data/Perl/Collection/Array/MooseLike.pm »