File Coverage

blib/lib/WebService/Linode.pm
Criterion Covered Total %
statement 18 64 28.1
branch 0 22 0.0
condition 0 3 0.0
subroutine 6 9 66.6
pod 1 1 100.0
total 25 99 25.2


line stmt bran cond sub pod time code
1             package WebService::Linode;
2              
3             require 5.006000;
4              
5 1     1   931 use warnings;
  1         2  
  1         54  
6 1     1   6 use strict;
  1         2  
  1         41  
7              
8 1     1   6 use Carp;
  1         1  
  1         89  
9 1     1   7 use List::Util qw(first);
  1         2  
  1         132  
10 1     1   6 use WebService::Linode::Base;
  1         2  
  1         518  
11              
12             our $VERSION = '0.27';
13             our @ISA = ("WebService::Linode::Base");
14             our $AUTOLOAD;
15              
16             # beginvalidation
17             my $validation = {
18             account => {
19             estimateinvoice => [ [ 'mode' ], [qw( linodeid paymentterm planid )] ],
20             info => [ [], [] ],
21             paybalance => [ [], [] ],
22             updatecard => [ [qw( ccexpmonth ccexpyear ccnumber )], [] ],
23             },
24             api => {
25             spec => [ [], [] ],
26             },
27             avail => {
28             datacenters => [ [], [] ],
29             distributions => [ [], [ 'distributionid' ] ],
30             kernels => [ [], [ 'isxen', 'kernelid' ] ],
31             linodeplans => [ [], [ 'planid' ] ],
32             nodebalancers => [ [], [] ],
33             stackscripts => [ [], [qw( distributionid distributionvendor keywords )] ],
34             },
35             domain => {
36             create => [ [ 'domain', 'type' ], [qw( axfr_ips description expire_sec lpm_displaygroup master_ips refresh_sec retry_sec soa_email status ttl_sec )] ],
37             delete => [ [ 'domainid' ], [] ],
38             list => [ [], [ 'domainid' ] ],
39             update => [ [ 'domainid' ], [qw( axfr_ips description domain expire_sec lpm_displaygroup master_ips refresh_sec retry_sec soa_email status ttl_sec type )] ],
40             },
41             domain_resource => {
42             create => [ [ 'domainid', 'type' ], [qw( name port priority protocol target ttl_sec weight )] ],
43             delete => [ [ 'domainid', 'resourceid' ], [] ],
44             list => [ [ 'domainid' ], [ 'resourceid' ] ],
45             update => [ [ 'resourceid' ], [qw( domainid name port priority protocol target ttl_sec weight )] ],
46             },
47             image => {
48             delete => [ [ 'imageid' ], [] ],
49             list => [ [], [ 'imageid', 'pending' ] ],
50             update => [ [ 'imageid' ], [ 'description', 'label' ] ],
51             },
52             linode => {
53             boot => [ [ 'linodeid' ], [ 'configid' ] ],
54             clone => [ [qw( datacenterid linodeid planid )], [ 'paymentterm' ] ],
55             create => [ [ 'datacenterid', 'planid' ], [ 'paymentterm' ] ],
56             delete => [ [ 'linodeid' ], [ 'skipchecks' ] ],
57             list => [ [], [ 'linodeid' ] ],
58             mutate => [ [ 'linodeid' ], [] ],
59             reboot => [ [ 'linodeid' ], [ 'configid' ] ],
60             resize => [ [ 'linodeid', 'planid' ], [] ],
61             shutdown => [ [ 'linodeid' ], [] ],
62             update => [ [ 'linodeid' ], [qw( alert_bwin_enabled alert_bwin_threshold alert_bwout_enabled alert_bwout_threshold alert_bwquota_enabled alert_bwquota_threshold alert_cpu_enabled alert_cpu_threshold alert_diskio_enabled alert_diskio_threshold backupweeklyday backupwindow label lpm_displaygroup ms_ssh_disabled ms_ssh_ip ms_ssh_port ms_ssh_user watchdog )] ],
63             webconsoletoken => [ [ 'linodeid' ], [] ],
64             },
65             linode_config => {
66             create => [ [qw( disklist kernelid label linodeid )], [qw( comments devtmpfs_automount helper_depmod helper_disableupdatedb helper_network helper_xen ramlimit rootdevicecustom rootdevicenum rootdevicero runlevel )] ],
67             delete => [ [ 'configid', 'linodeid' ], [] ],
68             list => [ [ 'linodeid' ], [ 'configid' ] ],
69             update => [ [ 'configid' ], [qw( comments devtmpfs_automount disklist helper_depmod helper_disableupdatedb helper_network helper_xen kernelid label linodeid ramlimit rootdevicecustom rootdevicenum rootdevicero runlevel )] ],
70             },
71             linode_disk => {
72             create => [ [qw( label linodeid size type )], [qw( fromdistributionid isreadonly rootpass rootsshkey )] ],
73             createfromdistribution => [ [qw( distributionid label linodeid rootpass size )], [ 'rootsshkey' ] ],
74             createfromimage => [ [ 'imageid', 'linodeid' ], [qw( label rootpass rootsshkey size )] ],
75             createfromstackscript => [ [qw( distributionid label linodeid rootpass size stackscriptid stackscriptudfresponses )], [ 'rootsshkey' ] ],
76             delete => [ [ 'diskid', 'linodeid' ], [] ],
77             duplicate => [ [ 'diskid', 'linodeid' ], [] ],
78             imagize => [ [ 'diskid', 'linodeid' ], [ 'description', 'label' ] ],
79             list => [ [ 'linodeid' ], [ 'diskid' ] ],
80             resize => [ [qw( diskid linodeid size )], [] ],
81             update => [ [ 'diskid' ], [qw( isreadonly label linodeid )] ],
82             },
83             linode_ip => {
84             addprivate => [ [ 'linodeid' ], [] ],
85             addpublic => [ [ 'linodeid' ], [] ],
86             list => [ [], [ 'ipaddressid', 'linodeid' ] ],
87             setrdns => [ [ 'hostname', 'ipaddressid' ], [] ],
88             swap => [ [ 'ipaddressid' ], [ 'tolinodeid', 'withipaddressid' ] ],
89             },
90             linode_job => {
91             list => [ [ 'linodeid' ], [ 'jobid', 'pendingonly' ] ],
92             },
93             nodebalancer => {
94             create => [ [ 'datacenterid' ], [ 'clientconnthrottle', 'label' ] ],
95             delete => [ [ 'nodebalancerid' ], [] ],
96             list => [ [], [ 'nodebalancerid' ] ],
97             update => [ [ 'nodebalancerid' ], [ 'clientconnthrottle', 'label' ] ],
98             },
99             nodebalancer_config => {
100             create => [ [ 'nodebalancerid' ], [qw( algorithm check check_attempts check_body check_interval check_path check_timeout port protocol ssl_cert ssl_key stickiness )] ],
101             delete => [ [ 'configid', 'nodebalancerid' ], [] ],
102             list => [ [ 'nodebalancerid' ], [ 'configid' ] ],
103             update => [ [ 'configid' ], [qw( algorithm check check_attempts check_body check_interval check_path check_timeout port protocol ssl_cert ssl_key stickiness )] ],
104             },
105             nodebalancer_node => {
106             create => [ [qw( address configid label )], [ 'mode', 'weight' ] ],
107             delete => [ [ 'nodeid' ], [] ],
108             list => [ [ 'configid' ], [ 'nodeid' ] ],
109             update => [ [ 'nodeid' ], [qw( address label mode weight )] ],
110             },
111             stackscript => {
112             create => [ [qw( distributionidlist label script )], [qw( description ispublic rev_note )] ],
113             delete => [ [ 'stackscriptid' ], [] ],
114             list => [ [], [ 'stackscriptid' ] ],
115             update => [ [ 'stackscriptid' ], [qw( description distributionidlist ispublic label rev_note script )] ],
116             },
117             test => {
118             echo => [ [], [] ],
119             },
120             user => {
121             getapikey => [ [ 'password', 'username' ], [qw( expires label token )] ],
122             },
123             };
124             # endvalidation
125              
126             sub AUTOLOAD {
127 0     0     ( my $name = $AUTOLOAD ) =~ s/.+:://;
128 0 0         return if $name eq 'DESTROY';
129 0 0         if ( $name =~ m/^(QUEUE_)?(.*?)_([^_]+)$/ ) {
130 0           my ( $queue, $thing, $action ) = ( $1, $2, $3 );
131 0 0 0       if ( exists $validation->{$thing} && exists $validation->{$thing}{$action} )
132 1     1   6 { no strict 'refs';
  1         1  
  1         450  
133 0           *{$AUTOLOAD} = sub {
134 0     0     my ( $self, %args ) = @_;
135 0           for my $req ( @{ $validation->{$thing}{$action}[0] } ) {
  0            
136 0 0         if ( !exists $args{$req} ) {
137 0           carp
138             "Missing required argument $req for ${thing}_${action}";
139 0           return;
140             }
141             }
142 0           for my $given ( keys %args ) {
143 0 0         if (!first { $_ eq $given }
  0            
144 0           @{ $validation->{$thing}{$action}[0] },
  0            
145             @{ $validation->{$thing}{$action}[1] } )
146 0           { carp "Unknown argument $given for ${thing}_${action}";
147 0           return;
148             }
149             }
150 0           ( my $apiAction = "${thing}_${action}" ) =~ s/_/./g;
151 0 0         return $self->queue_request( api_action => $apiAction, %args ) if $queue;
152 0           my $data = $self->do_request( api_action => $apiAction, %args );
153 0 0         return [ map { $self->_lc_keys($_) } @$data ]
  0            
154             if ref $data eq 'ARRAY';
155 0 0         return $self->_lc_keys($data) if ref $data eq 'HASH';
156 0           return $data;
157 0           };
158 0           goto &{$AUTOLOAD};
  0            
159             }
160             else {
161 0           carp "Can't call ${thing}_${action}";
162 0           return;
163             }
164 0           return;
165             }
166 0           croak "Undefined subroutine \&$AUTOLOAD called";
167             }
168              
169             sub send_queued_requests {
170 0     0 1   my $self = shift;
171 0           my $items = shift;
172              
173 0 0         if ( $self->list_queue == 0 ) {
174 0           $self->_error( -1, "No queued items to send" );
175 0           return;
176             }
177              
178 0           my @responses;
179 0           for my $data ( $self->process_queue( $items ) ) {
180 0 0         if ( ref $data eq 'ARRAY' ) {
    0          
181 0           push @responses, [ map { $self->_lc_keys($_) } @$data ];
  0            
182             } elsif( ref $data eq 'HASH' ) {
183 0           push @responses, $self->_lc_keys($data);
184             } else {
185 0           push @responses, $data;
186             }
187             }
188              
189 0           return @responses;
190             }
191              
192             'mmm, cake';
193             __END__