| 1 | package WebService::Strava::Athlete::Activity; | ||||||||||||||||||||||
| 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 Activity 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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_activity' ); | |||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 4 | has 'resource_state' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 59 | 4 | has 'indicates_level_of_detail' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 60 | 4 | has 'external_id' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 61 | 4 | has 'provided_at_upload' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 62 | 4 | has 'athlete' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 63 | 4 | has 'description' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 64 | 4 | has 'distance' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 65 | 4 | has 'moving_time' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 66 | 4 | has 'elapsed_time' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 67 | 4 | has 'total_elevation_gain' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 68 | 4 | has 'type' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 69 | 4 | has 'start_date' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 70 | 4 | has 'start_date_local' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 71 | 4 | has 'time_zone' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 72 | 4 | has 'start_latlng' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 73 | 4 | has 'end_latlng' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 74 | 4 | has 'location_city' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 75 | 4 | has 'location_state' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 76 | 4 | has 'location_country' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 77 | 4 | has 'achievement_count' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 78 | 4 | has 'kudos_count' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 79 | 4 | has 'comment_count' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 80 | 4 | has 'athlete_count' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 81 | 4 | has 'photo_count' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 82 | 4 | has 'map' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 83 | 4 | has 'trainer' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 84 | 4 | has 'commute' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 85 | 4 | has 'manual' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 86 | 4 | has 'private' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 87 | 4 | has 'flagged' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 88 | 4 | has 'workout_type' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 89 | 4 | has 'gear_id' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 90 | 4 | has 'gear' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 91 | 4 | has 'average_speed' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 92 | 4 | has 'meters_per_second' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 93 | 4 | has 'max_speed' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 94 | 4 | has 'average_cadence' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 95 | 4 | has 'average_temp' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 96 | 4 | has 'average_watts' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 97 | 4 | has 'kilojoules' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 98 | 4 | has 'average_heartrate' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 99 | 4 | has 'max_heartrate' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 100 | 4 | has 'calories' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 101 | 4 | has 'truncated' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 102 | 4 | has 'has_kudoed' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 103 | 4 | has 'segment_efforts' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 104 | 4 | has 'splits_metric' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 105 | 4 | has 'splits_standard' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 106 | 4 | has 'best_efforts' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | |||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | 0 | ▶ | if ($self->{_build}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 112 | 0 | $self->_build_activity(); | |||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||
| 114 | 0 | return; | |||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | 0 | ▶ | method _build_activity() { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
_build_activity: not called CC=2 SCAR=13.6
Branch: 1 branch
| |||||||||||||||||||||||
| 118 | 0 | my $activity = $self->auth->get_api("/activities/$self->{id}"); | |||||||||||||||||||||
| 119 | 0 | $self->_init_from_api($activity); | |||||||||||||||||||||
| 120 | 0 | return; | |||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | 0 | ▶ | method _init_from_api($activity) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.1
Subroutine
_init_from_api: not called CC=4 SCAR=27.5
Branch: 2 branches
| |||||||||||||||||||||||
| 124 | 0 | foreach my $key (keys %{ $activity }) { | |||||||||||||||||||||
| 125 | 0 | given ( $key ) { | |||||||||||||||||||||
| 126 | 0 | when ("athlete") { $self->_instantiate("Athlete", $key, $activity->{$key}); } | |||||||||||||||||||||
| 127 | 0 | when (/segment_efforts/) { $self->_instantiate("Athlete::Segment_Effort", $key, $activity->{$key}); } | |||||||||||||||||||||
| 128 | 0 | default { $self->{$key} = $activity->{$key}; } | |||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||
| 131 | |||||||||||||||||||||||
| 132 | 0 | return; | |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | 4 | ▶ | use WebService::Strava::Athlete; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 136 | 4 | ▶ | use WebService::Strava::Athlete::Segment_Effort; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 137 | |||||||||||||||||||||||
| 138 | 0 | ▶ | method _instantiate($type, $key, $data) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=5.3
Subroutine
_instantiate: not called CC=7 SCAR=38.5
Branch: 4 branches
| |||||||||||||||||||||||
| 139 | 0 | ▶ | if (ref($data) eq "ARRAY") { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 140 | 0 | my $index = 0; | |||||||||||||||||||||
| 141 | 0 | foreach my $item (@{$data}) { | |||||||||||||||||||||
| 142 | 0 | @{$data}[$index] = "WebService::Strava::$type"->new(auth => $self->auth, id => $item->{id}, _build => 0); | |||||||||||||||||||||
| 143 | 0 | $index++; | |||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||
| 145 | 0 | $self->{$key} = $data; | |||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||
| 147 | 0 | $self->{$key} = "WebService::Strava::$type"->new(auth => $self->auth, id => $data->{id}, _build => 0); | |||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||
| 149 | 0 | return; | |||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | |||||||||||||||||||||||
| 153 | 0 | ▶ | method retrieve() { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
retrieve: not called CC=2 SCAR=12.4
Branch: 1 branch
| |||||||||||||||||||||||
| 154 | 0 | $self->_build_activity(); | |||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||
| 156 | |||||||||||||||||||||||
| 157 | 4 | 1; | |||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||||