blib/lib/WWW/GoDaddy/REST/Shell.pm

filter: Statementstmt 40.5% 41 / 101 Branchbran 3.8% 1 / 26 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 68.4% 13 / 19 Podpod 0.0% 0 / 6 totaltotal 30.7% 55 / 179 CC 20 SCAR 47.7
CC
20
Cov
29%
init
272.0
schema_completion
20.0
client
6.0
CRAP 117.5
↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/QueryCommand.pm »
1 package WWW::GoDaddy::REST::Shell;
2 1 ▶use base qw(Term::Shell);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use List::Util qw(shuffle first);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use WWW::GoDaddy::REST;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use WWW::GoDaddy::REST::Shell::DocsCommand;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use WWW::GoDaddy::REST::Shell::GetCommand;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use WWW::GoDaddy::REST::Shell::ListCommand;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use WWW::GoDaddy::REST::Shell::QueryCommand;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶eval "use WWW::GoDaddy::REST::Shell::GraphCommand";
Subroutine BEGIN: called CC=1 SCAR=1.2
19 1 ▶if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 0 1
20 1 warn("Install the GraphViz module to enable the 'graph' command");
21 }
22  
23 sub init {
24 0 ▶ my $self = shift;
Subroutine init: not called CC=16 SCAR=56.1
Pod undocumented
25  
26 0 my %options;
27  
28 0 my $res
29 = GetOptions( \%options, "url=s", "config=s", "username=s", "password=s", "man", "help" );
30 0 ▶ pod2usage(2) if !$res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 0 0
31 0 ▶ pod2usage(1) if $options{help};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"help"} 0 0 0
32 0 ▶ pod2usage( -verbose => 2 ) if $options{man};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"man"} 0 0 0
33  
34 0 ▶ my $conf_file = $options{config} || '';
Condition0%0/2
$options{'config'} || ''
l!l
00
MC/DC0%0/1
$options{'config'} || ''
$options{'config'}
Truth table0%0/2
A
A= $options{'config'}
Aresult
11
00
35 0 ▶ if ( -e $conf_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $conf_file) 0 0 0
36 0 my $config = Config::Any->load_files(
37 { 'files' => [$conf_file],
38 'use_ext' => 1
39 }
40 )->[0];
41  
42 0 foreach (qw/ url username password /) {
43 0 ▶ $options{$_} ||= $config->{$conf_file}->{$_};
Condition0%0/3
$options{$_} ||= $config->{$conf_file}{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{$_} ||= $config->{$conf_file}{$_}
$options{$_} $config->{$conf_file}{$_}
Truth table0%0/3
A ||= B
A= $options{$_}B= $config->{$conf_file}{$_}
ABresult
1X1
011
000
44 }
45 }
46  
47 0 ▶ if ( $options{username} or $options{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"username"} or $options{"password"}) 0 0 0
Condition0%0/3
$options{"username"} or $options{"password"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"username"} or $options{"password"}
$options{"username"} $options{"password"}
Truth table0%0/3
A or B
A= $options{"username"}B= $options{"password"}
ABresult
1X1
011
000
48 0 ▶ if ( !$options{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"password"}) 0 0 0
49 0 pod2usage("You a username must also be provided");
50 }
51 0 ▶ if ( !$options{username} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"username"}) 0 0 0
52 0 pod2usage("You a password must also be provided");
53 }
54 }
55  
56 0 my $client_settings = { 'url' => $options{url} };
57 0 ▶ if ( $options{username} && $options{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"username"} and $options{"password"}) 0 0 0
Condition0%0/3
$options{"username"} and $options{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
$options{"username"} and $options{"password"}
$options{"username"} $options{"password"}
Truth table0%0/3
A and B
A= $options{"username"}B= $options{"password"}
ABresult
0X0
100
111
58 0 $client_settings->{'basic_username'} = $options{username};
59 0 $client_settings->{'basic_password'} = $options{password};
60 }
61  
62 0 ▶ if ( !$options{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"url"}) 0 0 0
63 0 pod2usage("The --url must be provided either on the command line or in the config file");
64 }
65  
66 0 my $client = eval { return WWW::GoDaddy::REST->new($client_settings) };
67 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
68 0 pod2usage($@);
69 }
70  
71 0 $self->client($client);
72  
73 0 return 1;
74 }
75  
76 sub preloop {
77 0 ▶ my ($self) = @_;
Subroutine preloop: not called CC=1 SCAR=6.9
Pod undocumented
78  
79 0 my $client = $self->client;
80  
81 my $random_schema
82 0 = ( shuffle map { $_->id } grep { $_->is_queryable } @{ $client->schemas } )[0];
83 0 my $url = $client->url;
84  
85 0 print "Tab completion is your friend.\n\n";
86 0 $self->run('list');
87 0 print "\n";
88 0 print "Some sample commands to get you started:\n";
89 0 print " list\n";
90 0 print " man $random_schema\n";
91 0 print " get $random_schema 1234\n";
92 0 print " get $url/schemas\n";
93  
94 }
95  
96 sub client {
97 0 ▶ my ( $self, $new ) = @_;
Subroutine client: not called CC=2 SCAR=17.9
Pod undocumented
98 0 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 0 0 0
99 0 $self->{SHELL}->{GDCLIENT} = $new;
100 }
101 0 return $self->{SHELL}->{GDCLIENT};
102 }
103  
104 sub prompt_str {
105 0 ▶ "api> ";
Subroutine prompt_str: not called CC=1 SCAR=6.9
Pod undocumented
106 }
107  
108 sub schema_completion {
109 0 ▶ my ( $self, $word, $line, $start ) = @_;
Subroutine schema_completion: not called CC=4 SCAR=30.0
Pod undocumented
110 0 my @words = $self->line_parsed($line);
111  
112 0 ▶ if ( @words > 2 or @words == 2 and $start == length($line) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@words > 2 or @words == 2 and $start == length $line) 0 0 0
Condition0%0/6
@words > 2 or @words == 2 and $start == length $line
l!l&&r!l&&!r
000
@words == 2 and $start == length $line
!ll&&!rl&&r
000
MC/DC0%0/3
@words > 2 or @words == 2 and $start == length $line
@words > 2 @words == 2 $start == length $line
Truth table0%0/4
A or B and C
A= @words > 2B= @words == 2C= $start == length $line
ABCresult
1XX1
0111
00X0
0100
113 0 return ();
114 }
115  
116 0 return grep { index( $_, $word ) == 0 } $self->schema_names();
117 }
118  
119 sub schema_names {
120 0 ▶ my ($self) = @_;
Subroutine schema_names: not called CC=1 SCAR=6.9
Pod undocumented
121 0 return sort map { $_->id } @{ $self->client->schemas };
122 }
123  
124 1 1;
125  
126 =head1 AUTHOR
127  
128 David Bartle, C<< <davidb@mediatemple.net> >>
129  
130 =head1 COPYRIGHT & LICENSE
131  
132 Copyright (c) 2014 Go Daddy Operating Company, LLC
133  
134 Permission is hereby granted, free of charge, to any person obtaining a
135 copy of this software and associated documentation files (the "Software"),
136 to deal in the Software without restriction, including without limitation
137 the rights to use, copy, modify, merge, publish, distribute, sublicense,
138 and/or sell copies of the Software, and to permit persons to whom the
139 Software is furnished to do so, subject to the following conditions:
140  
141 The above copyright notice and this permission notice shall be included in
142 all copies or substantial portions of the Software.
143  
144 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
145 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
146 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
147 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
148 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
149 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
150 DEALINGS IN THE SOFTWARE.
151  
152 =cut
153  
↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/QueryCommand.pm »