Analytics/Row.pm

filter: Statementstmt 97.5% 40 / 41 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 96.5% 56 / 58 CC 4 SCAR 5.3
CC
4
Cov
96%
get
3.1
_gen_class
2.0
BEGIN
1.0
CRAP 1.7
« Analytics/Response.pm ↑ Summary
1 package Net::Google::Analytics::Row;
2 2 $Net::Google::Analytics::Row::VERSION = '3.04';
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 BEGIN {
9 2 ▶ require Class::XSAccessor::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 }
11  
12 2 my $class_count = 0;
13  
14 # Dynamically generate a class with accessors
15 sub _gen_class {
16 3 ▶ my (undef, $column_headers) = @_;
Subroutine _gen_class: called CC=2 SCAR=6.9
17  
18 # Generate unique package name
19 3 my $class = "Net::Google::Analytics::Row_$class_count";
20 3 ++$class_count;
21  
22 {
23 # Set globals of new class
24 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 @{ "${class}::ISA" } = qw(Net::Google::Analytics::Row);
26 3 ${ "${class}::column_headers" } = $column_headers;
27 }
28  
29 # Create accessors
30 3 my %getters;
31 3 ▶ for (my $i = 0; $i < @$column_headers; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$column_headers) 9 3 12
32 9 my $getter = 'get_' . $column_headers->[$i]->{name};
33 9 $getters{$getter} = $i;
34 }
35 3 Class::XSAccessor::Array->import(
36 class => $class,
37 getters => \%getters,
38 );
39  
40 3 return $class;
41 }
42  
43 sub new {
44 12 ▶ my ($class, $row) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
45 12 return bless($row, $class);
46 }
47  
48 sub _column_headers {
49 1 ▶ my $self = shift;
Subroutine _column_headers: called CC=1 SCAR=0.0
50 1 my $class = ref($self);
51 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 return ${ "${class}::column_headers" };
53 }
54  
55 sub get {
56 1 ▶ my ($self, $name) = @_;
Subroutine get: called CC=3 SCAR=11.3
Pod documented
57  
58 1 my $column_headers = $self->_column_headers;
59  
60 1 ▶ for (my $i = 0; $i < @$column_headers; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$column_headers) 4 0 4
61 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
62 }
63  
64 0 return undef;
65 }
66  
67 2 1;
68  
69 __END__
« Analytics/Response.pm ↑ Summary