| 1 | package WebService::Strava::Athlete::Gear; | ||||||||||
| 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 namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | # ABSTRACT: An Athlete Gear Object | ||||||||||
| 15 | |||||||||||
| 16 | 4 | our $VERSION = '0.06'; # VERSION: Generated by DZP::OurPkg:Version | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | # Validation functions | ||||||||||
| 20 | |||||||||||
| 21 | 0 | ▶ | my $Ref = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 22 | 0 | ▶ | croak "auth isn't a 'WebService::Strava::Auth' object!" unless reftype( $_[0] )->class eq "WebService::Strava::Auth"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 4 | }; | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | my $Bool = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 26 | 0 | ▶ | croak "$_[0] must be 0|1" unless $_[0] =~ /^[01]$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 4 | }; | |||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | my $Id = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 30 | 0 | ▶ | croak "$_[0] doesn't appear to be a valid gear id" unless $_[0] =~ /^[bg]\d+/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 4 | }; | |||||||||
| 32 | |||||||||||
| 33 | # Debugging hooks in case things go weird. (Thanks @pjf) | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 36 | 0 | my $orig = shift; | |||||||||
| 37 | 0 | my $class = shift; | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | if ($WebService::Strava::DEBUG) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | warn "Building task with:\n"; | |||||||||
| 41 | 0 | warn Dumper(\@_), "\n"; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | return $class->$orig(@_); | |||||||||
| 45 | 4 | }; | |||||||||
| 46 | |||||||||||
| 47 | # Authentication Object | ||||||||||
| 48 | 4 | has 'auth' => ( is => 'ro', required => 1, isa => $Ref ); | |||||||||
| 49 | |||||||||||
| 50 | # Defaults + Required | ||||||||||
| 51 | 4 | has 'id' => ( is => 'ro', required => 1, isa => $Id); | |||||||||
| 52 | 0 | ▶ | has '_build' => ( is => 'ro', default => sub { 1 }, isa => $Bool ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 53 | |||||||||||
| 54 | 4 | has 'primary' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 55 | 4 | has 'name' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 56 | 4 | has 'distance' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 57 | 4 | has 'brand_name' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 58 | 4 | has 'model_name' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 59 | 4 | has 'description' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 60 | 4 | has 'resource_state' => ( is => 'ro', lazy => 1, builder => '_build_gear' ); | |||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 63 | 0 | my $self = shift; | |||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | if ($self->{_build}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 0 | $self->_build_gear(); | |||||||||
| 67 | } | ||||||||||
| 68 | 0 | return; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | method _build_gear() { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
_build_gear: not called CC=3 SCAR=20.7
Branch: 1 branch
| |||||||||||
| 72 | 0 | my $gear = $self->auth->get_api("/gear/$self->{id}"); | |||||||||
| 73 | |||||||||||
| 74 | 0 | foreach my $key (keys %{ $gear }) { | |||||||||
| 75 | 0 | $self->{$key} = $gear->{$key}; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | return; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | 0 | ▶ | method retrieve() { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
retrieve: not called CC=2 SCAR=12.4
Branch: 1 branch
| |||||||||||
| 83 | 0 | $self->_build_gear(); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 4 | 1; | |||||||||
| 87 | |||||||||||
| 88 | __END__ | ||||||||||