lib/Net/OneTimeSecret.pm

filter: Statementstmt 72.8% 43 / 59 Branchbran 100% 2 / 2 Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 61.1% 11 / 18 Podpod 50.0% 5 / 10 totaltotal 59.2% 67 / 113 CC 9 SCAR 9.6
CC
9
Cov
67%
shareSecret
4.8
_post
4.0
__url_for
3.6
CRAP 2.6
↑ Summary blib/lib/Net/example.pl »
1 package Net::OneTimeSecret;
2  
3 1 our $VERSION = "0.04";
4  
5 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Encode qw( encode_utf8 decode_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 my $_USER_AGENT = LWP::UserAgent->new();
12 1 my $_API_VERSION = "v1";
13 1 my $_BASE_URL = 'https://%s:%s@onetimesecret.com/api/'.$_API_VERSION;
14 1 my $_SECRET_TTL = 3600;
15  
16 1 ▶sub __url_for {
Subroutine __url_for: called CC=3 SCAR=12.7
17 1 my ($self, $action, $user, $password) = @_;
18 1 ▶ $user ||= $self->customerId();
Condition33%1/3
$user ||= $self->customerId
l!l&&r!l&&!r
010
MC/DC0%0/2
$user ||= $self->customerId
$user $self->customerId
Truth table33%1/3
A ||= B
A= $userB= $self->customerId
ABresult
1X1
011
000
19 1 ▶ $password ||= $self->apiKey();
Condition33%1/3
$password ||= $self->apiKey
l!l&&r!l&&!r
010
MC/DC0%0/2
$password ||= $self->apiKey
$password $self->apiKey
Truth table33%1/3
A ||= B
A= $passwordB= $self->apiKey
ABresult
1X1
011
000
20  
21 1 return sprintf(
22 $_BASE_URL,
23 uri_escape( $user ),
24 uri_escape( $password )
25 ) . $action;
26 }
27  
28 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
29 1 my $class = shift;
30 1 my $customerId = shift;
31 1 my $apiKey = shift;
32  
33 1 my %options = ( @_ );
34 1 my $self = bless {
35 _customerId => $customerId,
36 _apiKey => $apiKey,
37 }, $class;
38 # process other options...
39 1 return $self;
40 }
41  
42 1 ▶sub _post {
Subroutine _post: called CC=4 SCAR=13.9
43 1 my ($self, $url, $data) = @_;
44 1 ▶ $data ||= {};
Condition50%1/2
$data ||= {}
l!l
10
MC/DC0%0/1
$data ||= {}
$data
Truth table50%1/2
A
A= $data
Aresult
11
00
45 1 foreach my $key (keys %$data) {
46 4 ▶ delete $data->{$key} unless defined $data->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data->{$key} 2 2 4
47 }
48 1 my $response = $_USER_AGENT->post( $url, 'Content' => $data );
49 1 return from_json( decode_utf8( $response->decoded_content ) );
50 }
51  
52 0 ▶sub _get {
Subroutine _get: not called CC=1 SCAR=6.9
53 0 my ($self, $url) = @_;
54 0 my $response = $_USER_AGENT->get( $url );
55 0 return from_json( $response->decoded_content );
56 }
57  
58 0 ▶sub status {
Subroutine status: not called CC=1 SCAR=6.9
Pod documented
59 0 my ($self) = @_;
60 0 return $self->_get( $self->__url_for( "/status" ) );
61 }
62  
63 1 ▶sub shareSecret {
Subroutine shareSecret: called CC=4 SCAR=15.6
Pod documented
64 1 my $self = shift;
65 1 my $secret = shift;
66 1 my $options = { @_ };
67  
68 return $self->_post( $self->__url_for( "/share" ), {
69 secret => $secret,
70 ttl => $options->{ttl} || $_SECRET_TTL,
71 recipient => $options->{recipient} || undef,
72 passphrase => $options->{passphrase} || undef,
73 1 ▶ });
Condition42%3/7
$options->{'ttl'} || $_SECRET_TTL
l!l&&r!l&&!r
010
$options->{'recipient'} || undef
l!l
01
$options->{'passphrase'} || undef
l!l
01
MC/DC0%0/2
$options->{'ttl'} || $_SECRET_TTL
$options->{'ttl'} $_SECRET_TTL
MC/DC0%0/1
$options->{'recipient'} || undef
$options->{'recipient'}
MC/DC0%0/1
$options->{'passphrase'} || undef
$options->{'passphrase'}
Truth table33%1/3
A || B
A= $options->{'ttl'}B= $_SECRET_TTL
ABresult
1X1
011
000
Truth table50%1/2
A
A= $options->{'recipient'}
Aresult
11
00
Truth table50%1/2
A
A= $options->{'passphrase'}
Aresult
11
00
74 }
75  
76 0 ▶sub generateSecret {
Subroutine generateSecret: not called CC=1 SCAR=6.9
Pod documented
77 0 my $self = shift;
78 0 my $options = { @_ };
79  
80 0 return $self->_post( $self->__url_for( "/generate" ));
81 }
82  
83 0 ▶sub retrieveSecret {
Subroutine retrieveSecret: not called CC=1 SCAR=6.9
Pod documented
84 0 my $self = shift;
85 0 my $key = shift;
86 0 my $options = { @_ };
87 0 return $self->_post( $self->__url_for( sprintf("/secret/%s", $key) ), $options );
88 }
89  
90 0 ▶sub retrieveMetadata {
Subroutine retrieveMetadata: not called CC=1 SCAR=6.9
Pod documented
91 0 my ($self, $key) = @_;
92 0 return $self->_post( $self->__url_for( sprintf("/private/%s", $key) ) );
93 }
94  
95 1 ▶sub customerId { return $_[0]->{_customerId} };
Subroutine customerId: called CC=1 SCAR=0.0
Pod undocumented
96 0 ▶sub setCustomerId { $_[0]->{_customerId} = shift };
Subroutine setCustomerId: not called CC=1 SCAR=6.9
Pod undocumented
97 1 ▶sub apiKey { return $_[0]->{_apiKey} };
Subroutine apiKey: called CC=1 SCAR=0.0
Pod undocumented
98 0 ▶sub setApiKey { $_[0]->{_apiKey} = shift };
Subroutine setApiKey: not called CC=1 SCAR=6.9
Pod undocumented
99  
100 1 1;
101 __END__
↑ Summary blib/lib/Net/example.pl »