| 1 | package WebService::Bonusly::Base; | ||||||||||
| 2 | 1 | $WebService::Bonusly::Base::VERSION = '1.001'; | |||||||||
| 3 | 1 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Class::Load qw( load_class ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: A utility class for WebService::Bonusly | ||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | 1 | our $BONUSLY_API_URL = 'https://bonus.ly/api/v1/'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | has token => ( | |||||||||
| 14 | is => 'rw', | ||||||||||
| 15 | isa => 'Str', | ||||||||||
| 16 | required => 1, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | 1 | has base_url => ( | |||||||||
| 20 | is => 'ro', | ||||||||||
| 21 | isa => 'Str', | ||||||||||
| 22 | required => 1, | ||||||||||
| 23 | default => $BONUSLY_API_URL, | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | 1 | has ua => ( | |||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | required => 1, | ||||||||||
| 29 | lazy => 1, | ||||||||||
| 30 | builder => '_build_ua', | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | # Undocumented attribute, mostly useful for testing. Use at your own risk! | ||||||||||
| 34 | has _json_flags => ( | ||||||||||
| 35 | is => 'ro', | ||||||||||
| 36 | isa => 'HashRef', | ||||||||||
| 37 | required => 1, | ||||||||||
| 38 | 0 | ▶ | default => sub { {} }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | 1 | ); | |||||||||
| 40 | |||||||||||
| 41 | 1 | has debug => ( | |||||||||
| 42 | is => 'rw', | ||||||||||
| 43 | isa => 'Bool', | ||||||||||
| 44 | required => 1, | ||||||||||
| 45 | default => 0, | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub _build_ua { | ||||||||
|
Subroutine
_build_ua: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 0 | LWP::UserAgent->new( | |||||||||
| 50 | keep_alive => 1, | ||||||||||
| 51 | ); | ||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 8 | ▶ | sub _service_builder { | ||||||||
|
Subroutine
_service_builder: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 8 | my ($class, $service_name) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 8 | my $_build_service = "_build_$service_name"; | |||||||||
| 58 | 8 | ▶ | $class->meta->add_method("_build_$service_name" => sub { | ||||||||
|
Subroutine
_build_rewards: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 8 | my $self = shift; | |||||||||
| 60 | 8 | my $class_name = ucfirst $service_name; | |||||||||
| 61 | 8 | load_class("WebService::Bonusly::$class_name")->new( | |||||||||
| 62 | ws => $self, | ||||||||||
| 63 | ); | ||||||||||
| 64 | 8 | }); | |||||||||
| 65 | |||||||||||
| 66 | 8 | return $_build_service; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 252 | ▶ | sub print_debug { | ||||||||
|
Subroutine
print_debug: called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||
| 70 | 252 | ▶ | return unless $_[0]->debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 0 | shift; | |||||||||
| 72 | 0 | warn @_, "\n"; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||