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

filter: Statementstmt 39.8% 41 / 103 Branchbran 3.8% 1 / 26 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 68.4% 13 / 19 Podpod 0.0% 0 / 6 totaltotal 28.8% 55 / 191 CC 22 SCAR 50.5
CC
22
Cov
28%
init
342.0
schema_completion
20.0
client
6.0
CRAP 156.7
↑ 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=18 SCAR=58.3
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 # some config files specify the opts like this
47 0 ▶ $options{password} ||= $config->{$conf_file}->{basic_password};
Condition0%0/3
$options{"password"} ||= $config->{$conf_file}{"basic_password"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"password"} ||= $config->{$conf_file}{"basic_password"}
$options{"password"} $config->{$conf_file}{"basic_password"}
Truth table0%0/3
A ||= B
A= $options{"password"}B= $config->{$conf_file}{"basic_password"}
ABresult
1X1
011
000
48 0 ▶ $options{username} ||= $config->{$conf_file}->{basic_username};
Condition0%0/3
$options{"username"} ||= $config->{$conf_file}{"basic_username"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"username"} ||= $config->{$conf_file}{"basic_username"}
$options{"username"} $config->{$conf_file}{"basic_username"}
Truth table0%0/3
A ||= B
A= $options{"username"}B= $config->{$conf_file}{"basic_username"}
ABresult
1X1
011
000
49 }
50  
51 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
52 0 ▶ if ( !$options{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"password"}) 0 0 0
53 0 pod2usage("You a username must also be provided");
54 }
55 0 ▶ if ( !$options{username} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"username"}) 0 0 0
56 0 pod2usage("You a password must also be provided");
57 }
58 }
59  
60 0 my $client_settings = { 'url' => $options{url} };
61 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
62 0 $client_settings->{'basic_username'} = $options{username};
63 0 $client_settings->{'basic_password'} = $options{password};
64 }
65  
66 0 ▶ if ( !$options{url} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"url"}) 0 0 0
67 0 pod2usage("The --url must be provided either on the command line or in the config file");
68 }
69  
70 0 my $client = eval { return WWW::GoDaddy::REST->new($client_settings) };
71 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
72 0 pod2usage($@);
73 }
74  
75 0 $self->client($client);
76  
77 0 return 1;
78 }
79  
80 sub preloop {
81 0 ▶ my ($self) = @_;
Subroutine preloop: not called CC=1 SCAR=6.9
Pod undocumented
82  
83 0 my $client = $self->client;
84  
85 my $random_schema
86 0 = ( shuffle map { $_->id } grep { $_->is_queryable } @{ $client->schemas } )[0];
87 0 my $url = $client->url;
88  
89 0 print "Tab completion is your friend.\n\n";
90 0 $self->run('list');
91 0 print "\n";
92 0 print "Some sample commands to get you started:\n";
93 0 print " list\n";
94 0 print " man $random_schema\n";
95 0 print " get $random_schema 1234\n";
96 0 print " get $url/schemas\n";
97  
98 }
99  
100 sub client {
101 0 ▶ my ( $self, $new ) = @_;
Subroutine client: not called CC=2 SCAR=17.9
Pod undocumented
102 0 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 0 0 0
103 0 $self->{SHELL}->{GDCLIENT} = $new;
104 }
105 0 return $self->{SHELL}->{GDCLIENT};
106 }
107  
108 sub prompt_str {
109 0 ▶ "api> ";
Subroutine prompt_str: not called CC=1 SCAR=6.9
Pod undocumented
110 }
111  
112 sub schema_completion {
113 0 ▶ my ( $self, $word, $line, $start ) = @_;
Subroutine schema_completion: not called CC=4 SCAR=30.0
Pod undocumented
114 0 my @words = $self->line_parsed($line);
115  
116 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
117 0 return ();
118 }
119  
120 0 return grep { index( $_, $word ) == 0 } $self->schema_names();
121 }
122  
123 sub schema_names {
124 0 ▶ my ($self) = @_;
Subroutine schema_names: not called CC=1 SCAR=6.9
Pod undocumented
125 0 return sort map { $_->id } @{ $self->client->schemas };
126 }
127  
128 1 1;
129  
130 =head1 AUTHOR
131  
132 David Bartle, C<< <davidb@mediatemple.net> >>
133  
134 =head1 COPYRIGHT & LICENSE
135  
136 Copyright (c) 2014 Go Daddy Operating Company, LLC
137  
138 Permission is hereby granted, free of charge, to any person obtaining a
139 copy of this software and associated documentation files (the "Software"),
140 to deal in the Software without restriction, including without limitation
141 the rights to use, copy, modify, merge, publish, distribute, sublicense,
142 and/or sell copies of the Software, and to permit persons to whom the
143 Software is furnished to do so, subject to the following conditions:
144  
145 The above copyright notice and this permission notice shall be included in
146 all copies or substantial portions of the Software.
147  
148 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
149 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
151 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
152 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
153 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
154 DEALINGS IN THE SOFTWARE.
155  
156 =cut
157  
↑ Summary blib/lib/WWW/GoDaddy/REST/Shell/QueryCommand.pm »