Analytics/Row.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 96.9% 64 / 66 CC 5 SCAR 6.7
CC
5
Cov
96%
get
3.1
_gen_class
3.0
BEGIN
1.0
CRAP 1.9
« Analytics/Response.pm ↑ Summary
1 package Net::Google::Analytics::Row;
2 2 $Net::Google::Analytics::Row::VERSION = '3.05';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Base class for Google Analytics API result rows
7  
8 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 require Class::XSAccessor::Array;
10 }
11  
12 2 my $class_count = 0;
13 2 my %class_cache;
14  
15 # Dynamically generate a class with accessors
16 4 ▶sub _gen_class {
Subroutine _gen_class: called CC=3 SCAR=11.0
17 4 my (undef, $column_headers) = @_;
18  
19 # Cache lookup
20 4 my $cache_key = join("\t", map { $_->{name} } @$column_headers);
21 4 my $class = $class_cache{$cache_key};
22 4 ▶ return $class if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 1 3 4
23  
24 # Generate unique package name
25 3 $class = "Net::Google::Analytics::Row_$class_count";
26 3 ++$class_count;
27  
28 {
29 # Set globals of new class
30 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 @{ "${class}::ISA" } = qw(Net::Google::Analytics::Row);
32 3 ${ "${class}::column_headers" } = $column_headers;
33 }
34  
35 # Create accessors
36 3 my %getters;
37 3 ▶ for (my $i = 0; $i < @$column_headers; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$column_headers) 9 3 12
38 9 my $getter = 'get_' . $column_headers->[$i]->{name};
39 9 $getters{$getter} = $i;
40 }
41 3 Class::XSAccessor::Array->import(
42 class => $class,
43 getters => \%getters,
44 );
45  
46 # Store in cache
47 3 $class_cache{$cache_key} = $class;
48  
49 3 return $class;
50 }
51  
52 17 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
53 17 my ($class, $row) = @_;
54 17 return bless($row, $class);
55 }
56  
57 1 ▶sub _column_headers {
Subroutine _column_headers: called CC=1 SCAR=0.0
58 1 my $self = shift;
59 1 my $class = ref($self);
60 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
61 1 return ${ "${class}::column_headers" };
62 }
63  
64 1 ▶sub get {
Subroutine get: called CC=3 SCAR=11.3
Pod documented
65 1 my ($self, $name) = @_;
66  
67 1 my $column_headers = $self->_column_headers;
68  
69 1 ▶ for (my $i = 0; $i < @$column_headers; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$column_headers) 4 0 4
70 4 ▶ return $self->[$i] if $column_headers->[$i]->{name} eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $column_headers->[$i]{"name"} eq $name 1 3 4
71 }
72  
73 0 return undef;
74 }
75  
76 2 1;
77  
78 __END__
« Analytics/Response.pm ↑ Summary