blib/lib/WWW/Saucelabs.pm

filter: Statementstmt 100% 60 / 60 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 93.6% 89 / 95 CC 7 SCAR 5.7
CC
7
Cov
95%
__ANON__
3.0
__ANON__
3.0
fail_job
2.0
CRAP 1.8
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package WWW::Saucelabs;
4 1 $WWW::Saucelabs::VERSION = '0.0201';
5 # ABSTRACT: An incomplete, wip perl client to the Saucelabs REST API
6 1 ▶use Net::HTTP::Knork;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use JSON qw/to_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 has user => (
14 is => 'ro',
15 2 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
16 2 ▶ if (exists $ENV{SAUCE_USERNAME} && $ENV{SAUCE_USERNAME}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'SAUCE_USERNAME'} and $ENV{'SAUCE_USERNAME'}) { } 1 1 2
Condition66%2/3
exists $ENV{"SAUCE_USERNAME"} and $ENV{"SAUCE_USERNAME"}
!ll&&!rl&&r
101
MC/DC50%1/2
exists $ENV{"SAUCE_USERNAME"} and $ENV{"SAUCE_USERNAME"}
exists $ENV{"SAUCE_USERNAME"} $ENV{"SAUCE_USERNAME"}
Truth table66%2/3
A and B
A= exists $ENV{"SAUCE_USERNAME"}B= $ENV{"SAUCE_USERNAME"}
ABresult
0X0
100
111
17 1 return $ENV{SAUCE_USERNAME};
18 }
19 else {
20 1 croak 'You must specify a user, or set the environment variable SAUCE_USERNAME';
21 }
22 }
23 1 );
24  
25  
26 has access_key => (
27 is => 'ro',
28 3 ▶ default => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
29 3 ▶ if (exists $ENV{SAUCE_ACCESS_KEY} && $ENV{SAUCE_ACCESS_KEY}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{'SAUCE_ACCESS_KEY'} and $ENV{'SAUCE_ACCESS_KEY'}) { } 2 1 3
Condition66%2/3
exists $ENV{"SAUCE_ACCESS_KEY"} and $ENV{"SAUCE_ACCESS_KEY"}
!ll&&!rl&&r
102
MC/DC50%1/2
exists $ENV{"SAUCE_ACCESS_KEY"} and $ENV{"SAUCE_ACCESS_KEY"}
exists $ENV{"SAUCE_ACCESS_KEY"} $ENV{"SAUCE_ACCESS_KEY"}
Truth table66%2/3
A and B
A= exists $ENV{"SAUCE_ACCESS_KEY"}B= $ENV{"SAUCE_ACCESS_KEY"}
ABresult
0X0
100
111
30 2 return $ENV{SAUCE_ACCESS_KEY};
31 }
32 else {
33 1 croak 'You must specify an access_key, or set the environment variable SAUCE_ACCESS_KEY';
34 }
35 }
36 1 );
37  
38 1 my $methods = {};
39  
40  
41 $methods->{get_job_assets} = {
42 1 method => 'GET',
43 required_params => [ 'user', 'job_id' ],
44 path => '/:user/jobs/:job_id/assets',
45 };
46  
47  
48 $methods->{get_job_status} = {
49 1 method => 'GET',
50 required_params => [ 'user', 'job_id' ],
51 path => '/:user/jobs/job_id'
52 };
53  
54  
55 $methods->{get_jobs} = {
56 1 method => 'GET',
57 required_params => [ 'user' ],
58 optional_params => [ 'limit' ],
59 path => '/:user/jobs',
60 };
61  
62  
63 $methods->{set_job_status} = {
64 1 method => 'PUT',
65 required_params => [ 'user', 'job_id' ],
66 required_payload => [ 'status' ],
67 path => '/:user/jobs/:job_id'
68 };
69  
70  
71 $methods->{get_sauce_status} = {
72 1 method => 'GET',
73 base_url => 'http://saucelabs.com/rest/v1',
74 path => '/info/status',
75 };
76  
77 1 my $spec = {
78 name => 'Saucelabs REST API',
79 formats => [ 'json' ],
80 version => '0.1',
81 methods => $methods
82 };
83  
84 has _base_url => (
85 is => 'ro',
86 init_arg => undef,
87 lazy => 1,
88 10 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
89 10 my ($self) = @_;
90  
91 10 my $base_url = 'https://' . $self->user . ':' . $self->access_key;
92 10 $base_url .= '@saucelabs.com/rest/v1';
93  
94 10 return $base_url;
95 }
96 1 );
97  
98 has _spec => (
99 is => 'ro',
100 init_arg => undef,
101 lazy => 1,
102 9 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
103 9 my ($self) = @_;
104 9 $spec->{base_url} = $self->_base_url;
105 9 return $spec;
106 }
107 1 );
108  
109 has _client => (
110 is => 'ro',
111 lazy => 1,
112 1 handles => [ keys %{ $spec->{methods} } ],
113 7 ▶ builder => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
114 7 my ($self) = @_;
115  
116 7 my $knork = Net::HTTP::Knork->new(
117 spec => to_json($self->_spec),
118 client => $self->_ua,
119 default_params => {
120 user => $self->user
121 }
122 );
123  
124 7 return $knork;
125 }
126 1 );
127  
128 has _ua => (
129 is => 'ro',
130 14 ▶ default => sub { LWP::UserAgent->new }
Subroutine __ANON__: called CC=1 SCAR=0.0
131 1 );
132  
133  
134 2 ▶sub fail_job {
Subroutine fail_job: called CC=2 SCAR=7.1
Pod documented
135 2 my ($self, $job) = @_;
136 2 ▶ croak 'We need a job to fail' unless $job;
Branch: 1 branch
BranchTrueFalseTotal
unless $job 0 2 2
137  
138 2 $self->set_job_status({
139 job_id => $job,
140 status => JSON::false
141 });
142 }
143  
144  
145 2 ▶sub pass_job {
Subroutine pass_job: called CC=2 SCAR=7.1
Pod documented
146 2 my ($self, $job) = @_;
147 2 ▶ croak 'We need a job to pass' unless $job;
Branch: 1 branch
BranchTrueFalseTotal
unless $job 0 2 2
148  
149 2 $self->set_job_status({
150 job_id => $job,
151 status => JSON::true
152 });
153 }
154  
155 1 1;
156  
157 __END__
↑ Summary