| 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 | 0 | ▶ | eval "use WWW::GoDaddy::REST::Shell::GraphCommand"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | warn("Install the GraphViz module to enable the 'graph' command"); | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | pod2usage(1) if $options{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | pod2usage( -verbose => 2 ) if $options{man}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $conf_file = $options{config} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options{'config'} || ''
MC/DC0%0/1
$options{'config'} || ''
$options{'config'}
Truth table0%0/2
A
A= $options{'config'}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( -e $conf_file ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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}{$_}
MC/DC0%0/2
$options{$_} ||= $config->{$conf_file}{$_}
$options{$_}
$config->{$conf_file}{$_}
Truth table0%0/3
A ||= B
A= $options{$_}B= $config->{$conf_file}{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $options{username} ||= $config->{$conf_file}->{basic_username}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$options{"username"} ||= $config->{$conf_file}{"basic_username"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ( $options{username} or $options{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options{"username"} or $options{"password"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( !$options{password} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | pod2usage("You a username must also be provided"); | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ( !$options{username} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$options{"username"} and $options{"password"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | pod2usage($@); | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->client($client); | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub preloop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
preloop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub client { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
client: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ( $self, $new ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($new) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->{SHELL}->{GDCLIENT} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return $self->{SHELL}->{GDCLIENT}; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub prompt_str { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prompt_str: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | "api> "; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub schema_completion { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_completion: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my ( $self, $word, $line, $start ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @words = $self->line_parsed($line); | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ( @words > 2 or @words == 2 and $start == length($line) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
@words > 2 or @words == 2 and $start == length $line
@words == 2 and $start == length $line
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
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return grep { index( $_, $word ) == 0 } $self->schema_names(); | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub schema_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema_names: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||