line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Perl::Collection::Hash::MooseLike; |
2
|
|
|
|
|
|
|
$Data::Perl::Collection::Hash::MooseLike::VERSION = '0.001009'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Collection::Hash subclass that simulates Moose's native traits. |
4
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
5250
|
use strictures 1; |
|
6
|
|
|
|
|
8566
|
|
|
6
|
|
|
|
|
218
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
2791
|
use Role::Tiny::With; |
|
6
|
|
|
|
|
9539
|
|
|
6
|
|
|
|
|
316
|
|
8
|
6
|
|
|
6
|
|
2448
|
use Class::Method::Modifiers; |
|
6
|
|
|
|
|
7994
|
|
|
6
|
|
|
|
|
943
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Data::Perl::Role::Collection::Hash'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
around 'set', 'get', 'delete' => sub { |
13
|
|
|
|
|
|
|
my $orig = shift; |
14
|
|
|
|
|
|
|
my @res = $orig->(@_); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# support both class instance method invocation style |
17
|
|
|
|
|
|
|
@res = blessed($res[0]) |
18
|
|
|
|
|
|
|
&& ($res[0]->isa('Data::Perl::Collection::Hash') |
19
|
|
|
|
|
|
|
|| $res[0]->isa('Data::Perl::Collection::Array')) ? $res[0]->flatten : @res; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
wantarray ? @res : $res[-1]; |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
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 |
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 |
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 |
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 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Toby Inkster |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Matthew Phillips . |
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__ |