API.pm

filter: Statementstmt 64.8% 24 / 37 Branchbran n/a Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 63.6% 7 / 11 Podpod 100% 3 / 3 totaltotal 39.5% 34 / 86 CC 10 SCAR 40.2
CC
10
Cov
40%
new
110.0
__ANON__
2.0
user
2.0
CRAP 55.6
↑ Summary API/Base.pm »
1 #
2 # This file is part of GitHub-API
3 #
4 # This software is Copyright (c) 2013 by Chris Weyl.
5 #
6 # This is free software, licensed under:
7 #
8 # The GNU Lesser General Public License, Version 2.1, February 1999
9 #
10 package GitHub::API;
11 {
12 2 $GitHub::API::VERSION = '0.000000_03';
13 }
14  
15 2 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # ABSTRACT: An itty-bitty interface to the GitHub API
18  
19 2 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use IO::Socket::SSL 1.56;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Mozilla::CA;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use parent 'GitHub::API::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use aliased 'GitHub::API::User';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use aliased 'GitHub::API::Org';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # debugging...
28 #use Smart::Comments '###', '####';
29  
30  
31 0 ▶sub new {
Subroutine new: not called CC=10 SCAR=47.0
Pod documented
32 0 my ($class, %opts) = @_;
33  
34 0 ▶ $opts{user} //= $ENV{GH_USER} // `git config github.user`;
Condition0%0/6
$opts{"user"} //= $ENV{"GH_USER"} // `git config github.user`
l!l&&r!l&&!r
000
$ENV{"GH_USER"} // `git config github.user`
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts{"user"} //= $ENV{"GH_USER"} // `git config github.user`
$opts{"user"} $ENV{"GH_USER"} `git config github.user`
Truth table0%0/4
A //= B // C
A= $opts{"user"}B= $ENV{"GH_USER"}C= `git config github.user`
ABCresult
1XX1
01X1
0011
0000
35 0 ▶ $opts{token} //= $ENV{GH_TOKEN} // `git config github.token`;
Condition0%0/6
$opts{"token"} //= $ENV{"GH_TOKEN"} // `git config github.token`
l!l&&r!l&&!r
000
$ENV{"GH_TOKEN"} // `git config github.token`
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts{"token"} //= $ENV{"GH_TOKEN"} // `git config github.token`
$opts{"token"} $ENV{"GH_TOKEN"} `git config github.token`
Truth table0%0/4
A //= B // C
A= $opts{"token"}B= $ENV{"GH_TOKEN"}C= `git config github.token`
ABCresult
1XX1
01X1
0011
0000
36 0 ▶ $opts{url} //= q{};
Condition0%0/2
$opts{"url"} //= ""
l!l
00
MC/DC0%0/1
$opts{"url"} //= ""
$opts{"url"}
Truth table0%0/2
A
A= $opts{"url"}
Aresult
11
00
37 0 ▶ $opts{base_url} ||= 'https://api.github.com';
Condition0%0/2
$opts{"base_url"} ||= "https://api.github.com"
l!l
00
MC/DC0%0/1
$opts{"base_url"} ||= "https://api.github.com"
$opts{"base_url"}
Truth table0%0/2
A
A= $opts{"base_url"}
Aresult
11
00
38 $opts{ua} ||= HTTP::Tiny->new(
39 verify_ssl => 1,
40 agent => __PACKAGE__ . ' @ ',
41 0 ▶ %{ $opts{ua_opts} // {} },
Condition0%0/5
$opts{"ua"} ||= "HTTP::Tiny"->new("verify_ssl", 1, "agent", "GitHub::API \@ ", %{$opts{"ua_opts"} // {};})
l!l&&r!l&&!r
000
$opts{"ua_opts"} // {}
l!l
00
MC/DC0%0/2
$opts{"ua"} ||= "HTTP::Tiny"->new("verify_ssl", 1, "agent", "GitHub::API \@ ", %{$opts{"ua_opts"} // {};})
$opts{"ua"} "HTTP::Tiny"->new("verify_ssl", 1, "agent", "GitHub::API \@ ", %{$opts{"ua_opts"} // {};})
MC/DC0%0/1
$opts{"ua_opts"} // {}
$opts{"ua_opts"}
Truth table0%0/3
A ||= B
A= $opts{"ua"}B= "HTTP::Tiny"->new("verify_ssl", 1, "agent", "GitHub::API \@ ", %{$opts{"ua_opts"} // {};})
ABresult
1X1
011
000
Truth table0%0/2
A
A= $opts{"ua_opts"}
Aresult
11
00
42 );
43  
44 0 ▶ $opts{headers}->{Authorization} ||= "token $opts{token}";
Condition0%0/2
$opts{"headers"}{"Authorization"} ||= qq[token $opts{"token"}]
l!l
00
MC/DC0%0/1
$opts{"headers"}{"Authorization"} ||= qq[token $opts{"token"}]
$opts{"headers"}{"Authorization"}
Truth table0%0/2
A
A= $opts{"headers"}{"Authorization"}
Aresult
11
00
45 0 ▶ $opts{_req} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46  
47 ### fetching: $opts{url}
48 0 $opts{ua}->request(shift, $opts{url}, { headers => $opts{headers} }) };
49  
50 0 return bless \%opts, $class;
51 }
52  
53  
54 0 ▶sub user { shift->_next(User, '/user') }
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
55 #sub users { ... } # needs a Users class
56  
57 0 ▶sub org { shift->_next(Org, "/orgs/$_[0]") }
Subroutine org: not called CC=1 SCAR=6.9
Pod documented
58  
59 2 !!42;
60  
61 __END__
↑ Summary API/Base.pm »