| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Strava::Athlete::Activity; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 4 |  |  | 4 |  | 68 | use v5.010; | 
|  | 4 |  |  |  |  | 21 |  | 
|  | 4 |  |  |  |  | 227 |  | 
| 4 | 4 |  |  | 4 |  | 23 | use strict; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 163 |  | 
| 5 | 4 |  |  | 4 |  | 24 | use warnings; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 165 |  | 
| 6 | 4 |  |  | 4 |  | 23 | use Moo; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 35 |  | 
| 7 | 4 |  |  | 4 |  | 1463 | use Method::Signatures; | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 31 |  | 
| 8 | 4 |  |  | 4 |  | 1998 | use Scalar::Util qw(looks_like_number); | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 391 |  | 
| 9 | 4 |  |  | 4 |  | 23 | use Carp qw(croak); | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 218 |  | 
| 10 | 4 |  |  | 4 |  | 23 | use Scalar::Util::Reftype; | 
|  | 4 |  |  |  |  | 5 |  | 
|  | 4 |  |  |  |  | 206 |  | 
| 11 | 4 |  |  | 4 |  | 22 | use experimental 'switch'; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 30 |  | 
| 12 | 4 |  |  | 4 |  | 638 | use Data::Dumper; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 5740 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | # ABSTRACT: A Strava Activity Object | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | our $VERSION = '0.04'; # VERSION: Generated by DZP::OurPkg:Version | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # Validation functions | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | my $Ref = sub { | 
| 22 |  |  |  |  |  |  | croak "auth isn't a 'WebService::Strava::Auth' object!" unless reftype( $_[0] )->class eq "WebService::Strava::Auth"; | 
| 23 |  |  |  |  |  |  | }; | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | my $Bool = sub { | 
| 26 |  |  |  |  |  |  | croak "$_[0] must be 0|1" unless $_[0] =~ /^[01]$/; | 
| 27 |  |  |  |  |  |  | }; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | my $Num = sub { | 
| 30 |  |  |  |  |  |  | croak "$_[0] isn't a valid id" unless looks_like_number $_[0]; | 
| 31 |  |  |  |  |  |  | }; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Debugging hooks in case things go weird. (Thanks @pjf) | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | around BUILDARGS => sub { | 
| 36 |  |  |  |  |  |  | my $orig  = shift; | 
| 37 |  |  |  |  |  |  | my $class = shift; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | if ($WebService::Strava::DEBUG) { | 
| 40 |  |  |  |  |  |  | warn "Building task with:\n"; | 
| 41 |  |  |  |  |  |  | warn Dumper(\@_), "\n"; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | return $class->$orig(@_); | 
| 45 |  |  |  |  |  |  | }; | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | # Authentication Object | 
| 48 |  |  |  |  |  |  | has 'auth'            => ( is => 'ro', required => 1, isa => $Ref ); | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # Defaults + Required | 
| 51 |  |  |  |  |  |  | has 'id'                      => ( is => 'ro', required => 1, isa => $Num); | 
| 52 |  |  |  |  |  |  | has '_build'                  => ( is => 'ro', default => sub { 1 }, isa => $Bool ); | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # Segment Effort | 
| 55 |  |  |  |  |  |  | has 'name'                      => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | has 'resource_state'            => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 58 |  |  |  |  |  |  | has 'indicates level of detail' => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 59 |  |  |  |  |  |  | has 'external_id'               => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 60 |  |  |  |  |  |  | has 'provided at upload'        => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 61 |  |  |  |  |  |  | has 'athlete'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 62 |  |  |  |  |  |  | has 'description'               => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 63 |  |  |  |  |  |  | has 'distance'                  => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 64 |  |  |  |  |  |  | has 'moving_time'               => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 65 |  |  |  |  |  |  | has 'elapsed_time'              => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 66 |  |  |  |  |  |  | has 'total_elevation_gain'      => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 67 |  |  |  |  |  |  | has 'type'                      => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 68 |  |  |  |  |  |  | has 'start_date'                => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 69 |  |  |  |  |  |  | has 'start_date_local'          => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 70 |  |  |  |  |  |  | has 'time_zone'                 => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 71 |  |  |  |  |  |  | has 'start_latlng'              => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 72 |  |  |  |  |  |  | has 'end_latlng'                => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 73 |  |  |  |  |  |  | has 'location_city'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 74 |  |  |  |  |  |  | has 'location_state'            => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 75 |  |  |  |  |  |  | has 'location_country'          => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 76 |  |  |  |  |  |  | has 'achievement_count'         => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 77 |  |  |  |  |  |  | has 'kudos_count'               => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 78 |  |  |  |  |  |  | has 'comment_count'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 79 |  |  |  |  |  |  | has 'athlete_count'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 80 |  |  |  |  |  |  | has 'photo_count'               => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 81 |  |  |  |  |  |  | has 'map'                       => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 82 |  |  |  |  |  |  | has 'trainer'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 83 |  |  |  |  |  |  | has 'commute'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 84 |  |  |  |  |  |  | has 'manual'                    => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 85 |  |  |  |  |  |  | has 'private'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 86 |  |  |  |  |  |  | has 'flagged'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 87 |  |  |  |  |  |  | has 'workout_type'              => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 88 |  |  |  |  |  |  | has 'gear_id'                   => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 89 |  |  |  |  |  |  | has 'gear'                      => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 90 |  |  |  |  |  |  | has 'average_speed'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 91 |  |  |  |  |  |  | has 'meters per second'         => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 92 |  |  |  |  |  |  | has 'max_speed'                 => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 93 |  |  |  |  |  |  | has 'average_cadence'           => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 94 |  |  |  |  |  |  | has 'average_temp'              => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 95 |  |  |  |  |  |  | has 'average_watts'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 96 |  |  |  |  |  |  | has 'kilojoules'                => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 97 |  |  |  |  |  |  | has 'average_heartrate'         => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 98 |  |  |  |  |  |  | has 'max_heartrate'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 99 |  |  |  |  |  |  | has 'calories'                  => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 100 |  |  |  |  |  |  | has 'truncated'                 => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 101 |  |  |  |  |  |  | has 'has_kudoed'                => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 102 |  |  |  |  |  |  | has 'segment_efforts'           => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 103 |  |  |  |  |  |  | has 'splits_metric'             => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 104 |  |  |  |  |  |  | has 'splits_standard'           => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 105 |  |  |  |  |  |  | has 'best_efforts'              => ( is => 'ro', lazy => 1, builder => '_build_activity' ); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub BUILD { | 
| 108 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 109 |  |  |  |  |  |  |  | 
| 110 | 0 | 0 |  |  |  |  | if ($self->{_build}) { | 
| 111 | 0 |  |  |  |  |  | $self->_build_activity(); | 
| 112 |  |  |  |  |  |  | } | 
| 113 | 0 |  |  |  |  |  | return; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 | 4 | 0 |  | 4 |  | 9006 | method _build_activity() { | 
|  | 0 |  |  | 0 |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 117 | 0 |  |  |  |  |  | my $activity = $self->auth->get_api("/activities/$self->{id}"); | 
| 118 |  |  |  |  |  |  |  | 
| 119 | 0 |  |  |  |  |  | foreach my $key (keys %{ $activity }) { | 
|  | 0 |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | given ( $key ) { | 
| 121 | 0 |  |  |  |  |  | when      ("athlete")           { $self->_instantiate("Athlete", $key, $activity->{$key}); } | 
|  | 0 |  |  |  |  |  |  | 
| 122 | 0 |  |  |  |  |  | when      (/segment_efforts/)   { $self->_instantiate("Athlete::Segment_Effort", $key, $activity->{$key}); } | 
|  | 0 |  |  |  |  |  |  | 
| 123 | 0 |  |  |  |  |  | default                         { $self->{$key} = $activity->{$key}; } | 
|  | 0 |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  | } | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 0 |  |  |  |  |  | return; | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 4 |  |  | 4 |  | 1443 | use WebService::Strava::Athlete; | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 111 |  | 
| 131 | 4 |  |  | 4 |  | 20 | use WebService::Strava::Athlete::Segment_Effort; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 85 |  | 
| 132 |  |  |  |  |  |  |  | 
| 133 | 4 | 0 |  | 4 |  | 18771 | method _instantiate($type, $key, $data) { | 
|  | 0 | 0 |  | 0 |  |  |  | 
|  | 0 | 0 |  |  |  |  |  | 
|  | 0 | 0 |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 134 | 0 | 0 |  |  |  |  | if (ref($data) eq "ARRAY") { | 
| 135 | 0 |  |  |  |  |  | my $index = 0; | 
| 136 | 0 |  |  |  |  |  | foreach my $item (@{$data}) { | 
|  | 0 |  |  |  |  |  |  | 
| 137 | 0 |  |  |  |  |  | @{$data}[$index] = "WebService::Strava::$type"->new(auth => $self->auth, id => $item->{id}, _build => 0); | 
|  | 0 |  |  |  |  |  |  | 
| 138 | 0 |  |  |  |  |  | $index++; | 
| 139 |  |  |  |  |  |  | } | 
| 140 | 0 |  |  |  |  |  | $self->{$key} = $data; | 
| 141 |  |  |  |  |  |  | } else { | 
| 142 | 0 |  |  |  |  |  | $self->{$key} = "WebService::Strava::$type"->new(auth => $self->auth, id => $data->{id}, _build => 0); | 
| 143 |  |  |  |  |  |  | } | 
| 144 | 0 |  |  |  |  |  | return; | 
| 145 |  |  |  |  |  |  | } | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  |  | 
| 148 | 4 | 0 |  | 4 |  | 4128 | method retrieve() { | 
|  | 0 |  |  | 0 |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 149 | 0 |  |  |  |  |  | $self->_build_activity(); | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | 1; | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | __END__ | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =pod | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =encoding UTF-8 | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head1 NAME | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | WebService::Strava::Athlete::Activity - A Strava Activity Object | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head1 VERSION | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | version 0.04 | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | my $activity = WebService::Strava::Athlete::Activity->new( auth => $auth, id => '229781' ); | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | Upon instantiation will retrieve the activity matching the id. | 
| 175 |  |  |  |  |  |  | Requires a pre-authenticated WebService::Strava::Auth object. | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | =head1 METHODS | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =head2 retrieve() | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | $activity->retrieve(); | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | When a Activity object and is lazy loaded, you can call retrieve it by calling | 
| 184 |  |  |  |  |  |  | this method. | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =head1 AUTHOR | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | Leon Wright < techman@cpan.org > | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | This software is copyright (c) 2014 by Leon Wright. | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 195 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =cut |