VerticalResponse/Command.pm untested

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 155 CC 14 SCAR 31.3
CC
14
Cov
0%
AUTOLOAD
56.0
show_proc
42.0
createList_simple
12.0
CRAP 22.9
1 package Sash::Plugin::VerticalResponse::Command;
2  
3 use strict;
4 use warnings;
5  
6 # For the love of Singletons.
7 use base qw( Sash::Command );
8 use Sash::Plugin::VerticalResponse;
9 use Sash::Plugin::VerticalResponse::Cursor;
10  
11 use Carp;
12  
13 # Going straight to hell for this!
14 sub AUTOLOAD {
15 our $AUTOLOAD;
16  
17 if ( $AUTOLOAD =~ /::(\w*)\_(meth|proc)$/ ) {
18 my $args = __PACKAGE__->SUPER::_getCallerArgs ( shift, shift, $1 );
19
20 # Lets allow the user to enter 3 different types of arguments:
21 #
22 # 1. Any previously defined variable like $x which is scoped as $Sash::Command::x.
23 # Its up to the user to get the value as a hash ref correct.
24 # 2. Allow them to define an anonymous hash on the command line.
25 # 3. Allow them to supply the arugments separated by commas on the command line
26 # and we create the anonymous hash.
27 #
28 # This handles options 1 and 2
29 my $hash = __PACKAGE__->SUPER::_bringVarIntoScope( $args );
30
31 # Handle option 3 if necessary.
32 unless( defined $hash && ref $hash eq 'HASH' ) {
33 # The coderef for the simple method.
34 my $simple_method = \&{__PACKAGE__ . "::${1}_simple"};
35  
36 # Get the hash from the arguments and the simple syntax interface.
37 $hash = $simple_method->( $args ) unless defined $hash && ref $hash eq 'HASH';
38 }
39
40 __PACKAGE__->SUPER::begin;
41
42 my $cursor = Sash::Plugin::VerticalResponse::Cursor->open( {
43 query => $hash,
44 caller => "${1}_meth"
45 } );
46
47 my $result = $cursor->fetch;
48
49 $cursor->close;
50
51 return __PACKAGE__->SUPER::end( { result => $result } );
52 }
53
54 return "Bah! No documentation here.\n" if ( $AUTOLOAD =~ /::(\w*)_doc$/ );
55
56 return "No description for $1\n" if ( $AUTOLOAD =~ /::(\w*)_desc$/ );
57
58 return "No simple syntax for $1\n" if ( $AUTOLOAD =~ /::(\w*)_simple$/ );
59 }
60  
61 sub get_command_hash {
62 my $class = shift;
63  
64 my $command_hash = Sash::CommandHash->new( $class );
65  
66 my $parent_commands = $class->SUPER::get_command_hash;
67  
68 my $base_commands = {
69 '' => { meth => \&Sash::Plugin::VerticalResponse::Command::default_command },
70 show => $command_hash->build( { use => 'show' } ),
71 refresh => { syn => 'reconnect' },
72 };
73
74 my @supported_methods = qw(
75 addListMember
76 calculateCampaignAudience
77 createCompany
78 createList
79 createUser
80 deleteList
81 deleteListMember
82 downloadCampaignRecipientResults
83 downloadCampaignRecipientResultsBackground
84 downloadList
85 downloadListBackground
86 editCompany
87 editListAttribute
88 editListMember
89 editUser
90 enumerateCompanies
91 enumerateLists
92 eraseListMembers
93 getCampaignDomainCount
94 getCompany
95 getListDomainCount
96 getListMemberByAddressHash
97 getListMemberByEmailAddress
98 getListMemberByHash
99 getListMembers
100 getUser
101 getUserByEmailAddress
102 renderCampaignContent
103 searchListMembers
104 setCustomListFields
105 setDisplayedListFields
106 setIndexedListFields
107 validateStreetAddress
108 );
109
110 my $commands = { map { $_ => $command_hash->build( { use => $_, proc => 'meth' } ) } @supported_methods };
111  
112 # Give back the merged result.
113 return { %{$parent_commands}, %{$base_commands}, %{$commands} };
114 }
115  
116 sub calculateCampaignAudience_simple {
117 return { campaign_id => shift };
118 }
119  
120 sub createList_simple {
121 my $args = shift;
122
123 my @tokens = split /\W*,\W*/, $args;
124 my $list_name = shift @tokens;
125 my $list_type = shift @tokens;
126 my $custom_field_names = [ @tokens ] if @tokens;
127
128 my $hash = { name => $list_name, type => $list_type };
129 $hash->{custom_field_names} = $custom_field_names if defined $custom_field_names;
130
131 return $hash;
132 }
133  
134 sub deleteList_simple {
135 return { list_id => shift };
136 }
137  
138 sub enumerateLists_simple {
139 return { list_id => shift };
140 }
141  
142 sub getCompany_simple {
143 my ( $company_id, $include_users ) = split /\W*,\W*/, shift;
144 return { company_id => $company_id, include_users => $include_users };
145 }
146  
147 sub getListMembers_simple {
148 return { list_id => shift, max_records => 100 };
149 }
150  
151 sub getUser_simple {
152 return { user_id => shift };
153 }
154  
155 sub getUserByEmailAddress_simple {
156 return { email_address => shift };
157 }
158  
159 sub show_proc {
160 ( my $which = shift ) =~ s/(.*?);?/$1/g;
161  
162 my $values = 'methods|username|endpoint|password';
163
164 croak "usage: show $values\n" unless ( $which =~ /^$values$/ );
165  
166 if ( $which =~ /methods/ ) {
167 __PACKAGE__->SUPER::begin;
168
169 my $cursor = Sash::Plugin::VerticalResponse::Cursor->open( {
170 query => $which,
171 caller => 'show_proc'
172 } );
173  
174 my $result = $cursor->fetch;
175  
176 $cursor->close;
177  
178 __PACKAGE__->SUPER::end( { result => $result } );
179 }
180
181 print Sash::Plugin::VerticalResponse->username . "\n" if $which eq 'username';
182 print Sash::Plugin::VerticalResponse->password . "\n" if $which eq 'password';
183 print Sash::Plugin::VerticalResponse->endpoint . "\n" if $which eq 'endpoint';
184  
185 return;
186 }
187  
188 sub default_command {
189 my $term = shift;
190 my $args = shift;
191
192 $args->{cursor_class} = 'Sash::Plugin::VerticalResponse::Cursor';
193
194 return __PACKAGE__->SUPER::default_command( $term, $args );
195 }
196  
197  
198 1;