Strava/Athlete/Segment_Effort.pm

filter: Statementstmt 63.9% 71 / 111 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.0% 16 / 25 Podpod 0.0% 0 / 1 totaltotal 54.7% 87 / 159 CC 13 SCAR 18.2
CC
13
Cov
53%
_instantiate
23.2
_build_effort
9.2
__ANON__
6.0
CRAP 6.2
« Strava/Athlete/Activity.pm ↑ Summary Strava/Athlete/Gear.pm »
1 package WebService::Strava::Athlete::Segment_Effort;
2  
3 4 ▶use v5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Scalar::Util::Reftype;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Method::Signatures 20140224;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use experimental 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: A Strava Segment Effort Object
16  
17 4 our $VERSION = '0.06'; # VERSION: Generated by DZP::OurPkg:Version
18  
19  
20 # Validation functions
21  
22 0 ▶my $Ref = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
23 0 ▶ croak "auth isn't a 'WebService::Strava::Auth' object!" unless reftype( $_[0] )->class eq "WebService::Strava::Auth";
Branch: 1 branch
BranchTrueFalseTotal
unless reftype($_[0])->class eq "WebService::Strava::Auth" 0 0 0
24 4 };
25  
26 0 ▶my $Bool = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
27 0 ▶ croak "$_[0] must be 0|1" unless $_[0] =~ /^[01]$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^[01]$/ 0 0 0
28 4 };
29  
30 0 ▶my $Num = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
31 0 ▶ croak "$_[0] isn't a valid id" unless looks_like_number $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($_[0]) 0 0 0
32 4 };
33  
34 # Debugging hooks in case things go weird. (Thanks @pjf)
35  
36 0 ▶around BUILDARGS => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
37 0 my $orig = shift;
38 0 my $class = shift;
39
40 0 ▶ if ($WebService::Strava::DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebService::Strava::DEBUG) 0 0 0
41 0 warn "Building task with:\n";
42 0 warn Dumper(\@_), "\n";
43 }
44
45 0 return $class->$orig(@_);
46 4 };
47  
48 # Authentication Object
49 4 has 'auth' => ( is => 'ro', required => 1, isa => $Ref );
50  
51 # Defaults + Required
52 4 has 'id' => ( is => 'ro', required => 1, isa => $Num);
53 0 ▶has '_build' => ( is => 'ro', default => sub { 1 }, isa => $Bool );
Subroutine __ANON__: not called CC=1 SCAR=1.2
54  
55 # Segment Effort
56 4 has 'name' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
57 4 has 'resource_state' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
58 4 has 'activity' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
59 4 has 'elapsed_time' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
60 4 has 'moving_time' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
61 4 has 'start_date' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
62 4 has 'start_date_local' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
63 4 has 'distance' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
64 4 has 'start_index' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
65 4 has 'end_index' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
66 4 has 'average_cadence' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
67 4 has 'average_watts' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
68 4 has 'average_heartrate' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
69 4 has 'max_heartrate' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
70 4 has 'segment' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
71 4 has 'kom_rank' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
72 4 has 'pr_rank' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
73 4 has 'hidden' => ( is => 'ro', lazy => 1, builder => '_build_effort' );
74  
75 0 ▶sub BUILD {
Subroutine BUILD: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $self = shift;
77  
78 0 ▶ if ($self->{_build}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_build"}) 0 0 0
79 0 $self->_build_effort();
80 }
81 0 return;
82 }
83  
84 0 ▶method _build_effort() {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine _build_effort: not called CC=3 SCAR=22.2
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
85 0 my $effort = $self->auth->get_api("/segment_efforts/$self->{id}");
86
87 0 foreach my $key (keys %{ $effort }) {
88 0 given ( $key ) {
89 0 when (/athlete/) { $self->_instantiate("Athlete", $key, $effort->{$key}); }
90 0 when (/segment/) { $self->_instantiate("Segment", $key, $effort->{$key}); }
91 0 default { $self->{$key} = $effort->{$key}; }
92 }
93 }
94  
95 0 return;
96 }
97  
98 4 ▶use WebService::Strava::Athlete;
Subroutine BEGIN: called CC=1 SCAR=0.0
99 4 ▶use WebService::Strava::Segment;
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 0 ▶method _instantiate($type, $key, $data) {
Subroutine BEGIN: called CC=1 SCAR=5.3
Subroutine _instantiate: not called CC=5 SCAR=31.5
Branch: 4 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
unless scalar @_ > 1 0 0 0
unless scalar @_ > 2 0 0 0
if scalar @_ > 3 0 0 0
102 0 $self->{$key} = "WebService::Strava::$type"->new(auth => $self->auth, id => $data->{id}, _build => 0);
103 0 return;
104 }
105  
106  
107 0 ▶method retrieve() {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine retrieve: not called CC=2 SCAR=12.4
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
108 0 $self->_build_effort();
109 }
110  
111 4 1;
112  
113 __END__
« Strava/Athlete/Activity.pm ↑ Summary Strava/Athlete/Gear.pm »