File Coverage

blib/lib/WWW/RabbitMQ/Broker/Shovel.pm
Criterion Covered Total %
statement 6 39 15.3
branch 0 10 0.0
condition 0 5 0.0
subroutine 2 8 25.0
pod 6 6 100.0
total 14 68 20.5


line stmt bran cond sub pod time code
1             package WWW::RabbitMQ::Broker::Shovel;
2              
3 1     1   4 use strict;
  1         2  
  1         41  
4 1     1   5 use warnings;
  1         1  
  1         691  
5              
6             our $VERSION = '0.03';
7              
8             sub new
9             {
10 0     0 1   my $class = shift;
11 0           my $broker = shift;
12              
13 0 0         my $self = {
14             _config => ref($_[0]) ? $_[0] : {@_},
15             };
16              
17 0 0 0       unless ($broker && ref($broker) eq 'WWW::RabbitMQ::Broker') {
18 0           die "ERROR: Did not receive a proper broker object.\n";
19             }
20              
21 0   0       $self->{_config}{vhost} ||= '/';
22 0           $self->{_broker} = $broker;
23 0           return bless($self, $class);
24             }
25              
26             sub delete
27             {
28 0     0 1   my $self = shift;
29 0           $self->{_broker}->httpMethod('DELETE')->apiCall("parameters/shovel/$self->{_config}{vhost}/$self->{_config}{name}");
30 0           return {deleted => 1};
31             }
32              
33             sub get
34             {
35 0     0 1   my $self = shift;
36 0           my $res = $self->{_broker}->httpMethod('GET')->apiCall("parameters/shovel/$self->{_config}{vhost}/$self->{_config}{name}");
37 0           return $self->{_config} = $res;
38             }
39              
40             sub getConfig
41             {
42 0     0 1   my $self = shift;
43 0           my $get = shift;
44 0           $self->get;
45 0 0         if ($get eq 'all') {
46 0           return $self->{_config};
47             }
48             else {
49 0           return $self->{_config}{$get};
50             }
51             }
52              
53             sub getOrPut
54             {
55 0     0 1   my $self = shift;
56              
57 0           my $res;
58 0           eval {
59 0           $res = $self->{_broker}->httpMethod('GET')->apiCall("parameters/shovel/$self->{_config}{vhost}/$self->{_config}{name}");
60             };
61              
62 0 0         if ($!) {
63 0 0         unless ($! =~ /Invalid/) {
64 0           die "ERROR[404]: Invalid Method\n";
65             }
66 0           my $res = $self->{_broker}->httpMethod('PUT')->apiCall(
67             "parameters/shovel/$self->{_config}{vhost}/$self->{_config}{name}",
68             $self->{_config},
69             );
70 0           return $self->{_config} = $res;
71             }
72             else {
73 0           return $self->{_config} = $res;
74             }
75             }
76              
77             sub put
78             {
79 0     0 1   my $self = shift;
80 0           my $res = $self->{_broker}->httpMethod('PUT')->apiCall(
81             "parameters/shovel/$self->{_config}{vhost}/$self->{_config}{name}",
82             $self->{_config},
83             );
84 0           return $self->{_config} = $res;
85             }
86              
87             1;
88              
89             __END__