blib/lib/Class/Accessor/Contextual.pm

filter: Statementstmt 93.7% 15 / 16 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 88.8% 24 / 27 CC 4 SCAR 10.6
CC
4
Cov
86%
get
4.3
BEGIN
1.0
BEGIN
1.0
CRAP 2.9
↑ Summary
1 package Class::Accessor::Contextual;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Class::Accessor::Contextual - Context-aware accessors
9  
10 =cut
11  
12 2 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<< <bduggan at matatu.org> >>
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 ▶use base 'Class::Accessor';
Subroutine BEGIN: called CC=1 SCAR=0.0
63  
64 3 ▶sub get {
Subroutine get: called CC=4 SCAR=14.6
Pod documented
65 3 my $got = shift->SUPER::get(@_);
66 3 ▶ return $got unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 3 3
67 3 ▶ return @$got if ref($got) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $got eq "ARRAY" 2 1 3
68 1 ▶ return %$got if ref($got) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $got eq "HASH" 1 0 1
69 0 return $got;
70 }
71  
72 2 1;
↑ Summary