line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Accessor::Contextual; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49497
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
234
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Class::Accessor::Contextual - Context-aware accessors |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Farm; |
17
|
|
|
|
|
|
|
use base qw/Class::Accessor::Contextual/; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Farm->mk_accessors(qw/animals names/); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $farm = Farm->new(); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$farm->animals([qw/horse pig owl/]); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
print join ' ', $farm->animals; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# horse pig owl |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$farm->names({ |
30
|
|
|
|
|
|
|
horse => "Mr. Ed", |
31
|
|
|
|
|
|
|
pig => "Miss Piggy", |
32
|
|
|
|
|
|
|
owl => "Dr. Who"}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my %name_hash = $farm->names; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This class overrides Class::Accessor's get() method |
39
|
|
|
|
|
|
|
so that references to arrays or hashes will automatically |
40
|
|
|
|
|
|
|
be dereferenced when called in list context. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 AUTHOR |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Brian Duggan, C<< >> |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SEE ALSO |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Class::Accessor |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Copyright 2009 Brian Duggan. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
55
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
56
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
|
14
|
use base 'Class::Accessor'; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
2103
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get { |
65
|
3
|
|
|
3
|
1
|
1428
|
my $got = shift->SUPER::get(@_); |
66
|
3
|
50
|
|
|
|
24
|
return $got unless wantarray; |
67
|
3
|
100
|
|
|
|
19
|
return @$got if ref($got) eq 'ARRAY'; |
68
|
1
|
50
|
|
|
|
15
|
return %$got if ref($got) eq 'HASH'; |
69
|
0
|
|
|
|
|
|
return $got; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |