RabbitFoot/Cmd/Role/Command.pm

filter: Statementstmt 33.3% 21 / 63 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 2 totaltotal 23.3% 25 / 107 CC 11 SCAR 21.6
CC
11
Cov
25%
validate_args
20.0
_validate_vhost
12.0
_check_queue
12.0
CRAP 8.6
↑ Summary RabbitFoot/Cmd/Role/Config.pm »
1 package Net::RabbitFoot::Cmd::Role::Command;
2  
3 1 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::RabbitFoot;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 requires qw(_run);
8  
9 1 has spec => (
10 isa => 'Str',
11 is => 'rw',
12 default => '',
13 metaclass => 'MooseX::Getopt::Meta::Attribute',
14 cmd_aliases => 's',
15 documentation => 'AMQP specification',
16 );
17  
18 1 has host => (
19 isa => 'Str',
20 is => 'rw',
21 default => 'localhost',
22 metaclass => 'MooseX::Getopt::Meta::Attribute',
23 cmd_aliases => 'H',
24 documentation => 'host name or ip address',
25 );
26  
27 1 has port => (
28 isa => 'Int',
29 is => 'rw',
30 default => 5672,
31 metaclass => 'MooseX::Getopt::Meta::Attribute',
32 cmd_aliases => 'P',
33 documentation => 'port number',
34 );
35  
36 1 has user => (
37 isa => 'Str',
38 is => 'rw',
39 default => 'guest',
40 metaclass => 'MooseX::Getopt::Meta::Attribute',
41 cmd_aliases => 'u',
42 documentation => 'user name',
43 );
44  
45 1 has pass => (
46 isa => 'Str',
47 is => 'rw',
48 default => 'guest',
49 metaclass => 'MooseX::Getopt::Meta::Attribute',
50 cmd_aliases => 'p',
51 documentation => 'password',
52 );
53  
54 1 has vhost => (
55 isa => 'Str',
56 is => 'rw',
57 default => '/',
58 metaclass => 'MooseX::Getopt::Meta::Attribute',
59 cmd_aliases => 'v',
60 documentation => 'virtual host',
61 );
62  
63 1 has verbose => (
64 isa => 'Bool',
65 is => 'rw',
66 metaclass => 'MooseX::Getopt::Meta::Attribute',
67 cmd_aliases => 'V',
68 documentation => 'Verbose mode',
69 );
70  
71 1 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 0 ▶sub validate_args {
Subroutine validate_args: not called CC=4 SCAR=30.0
Pod undocumented
74 0 my ($self, $opt, $args) = @_;
75  
76 0 for my $method ($self->meta->get_all_methods) {
77 0 ▶ next if $method->name !~ /^_validate_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $method->name =~ /^_validate_/ 0 0 0
78 0 eval {$method->execute($self);};
79 0 ▶ die $self->usage_error($@) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
80 }
81 }
82  
83 0 ▶sub _validate_spec {
Subroutine _validate_spec: not called CC=2 SCAR=17.9
84 0 my ($self,) = @_;
85  
86 0 ▶ die 'spec', "\n" if !-f $self->spec;
Branch: 1 branch
BranchTrueFalseTotal
if not -f $self->spec 0 0 0
87 }
88  
89 0 ▶sub _validate_vhost {
Subroutine _validate_vhost: not called CC=3 SCAR=24.8
90 0 my ($self,) = @_;
91  
92 0 ▶ die 'vhost', "\n"
Branch: 1 branch
BranchTrueFalseTotal
if 255 < length $self->vhost or not $self->vhost =~ m[^[a-zA-Z0-9/\-_]+$] 0 0 0
Condition0%0/3
255 < length $self->vhost or not $self->vhost =~ m[^[a-zA-Z0-9/\-_]+$]
l!l&&r!l&&!r
000
MC/DC0%0/2
255 < length $self->vhost or not $self->vhost =~ m[^[a-zA-Z0-9/\-_]+$]
255 < length $self->vhost not $self->vhost =~ m[^[a-zA-Z0-9/\-_]+$]
Truth table0%0/3
A or not(B)
A= 255 < length $self->vhostB= not $self->vhost =~ m[^[a-zA-Z0-9/\-_]+$]
ABresult
1X1
011
000
93 if 255 < length($self->vhost)
94 || $self->vhost !~ m{^[a-zA-Z0-9/\-_]+$};
95 }
96  
97 0 ▶sub _check_queue {
Subroutine _check_queue: not called CC=3 SCAR=24.8
98 0 my ($self,) = @_;
99  
100 0 ▶ die 'queue', "\n"
Branch: 1 branch
BranchTrueFalseTotal
if 255 < length $self->queue or not $self->queue =~ m[^[a-zA-Z0-9/\-_.:=+]+$] 0 0 0
Condition0%0/3
255 < length $self->queue or not $self->queue =~ m[^[a-zA-Z0-9/\-_.:=+]+$]
l!l&&r!l&&!r
000
MC/DC0%0/2
255 < length $self->queue or not $self->queue =~ m[^[a-zA-Z0-9/\-_.:=+]+$]
255 < length $self->queue not $self->queue =~ m[^[a-zA-Z0-9/\-_.:=+]+$]
Truth table0%0/3
A or not(B)
A= 255 < length $self->queueB= not $self->queue =~ m[^[a-zA-Z0-9/\-_.:=+]+$]
ABresult
1X1
011
000
101 if 255 < length($self->queue)
102 || $self->queue !~ m{^[a-zA-Z0-9/\-_.:=+]+$};
103 }
104  
105 0 ▶sub _check_shortstr {
Subroutine _check_shortstr: not called CC=3 SCAR=24.8
106 0 my ($self, $arg,) = @_;
107  
108 0 ▶ die $arg, "\n"
Branch: 1 branch
BranchTrueFalseTotal
if 255 < length $self->$arg or not $self->$arg =~ /^[a-zA-Z0-9-_.:]+$/ 0 0 0
Condition0%0/3
255 < length $self->$arg or not $self->$arg =~ /^[a-zA-Z0-9-_.:]+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
255 < length $self->$arg or not $self->$arg =~ /^[a-zA-Z0-9-_.:]+$/
255 < length $self->$arg not $self->$arg =~ /^[a-zA-Z0-9-_.:]+$/
Truth table0%0/3
A or not(B)
A= 255 < length $self->$argB= not $self->$arg =~ /^[a-zA-Z0-9-_.:]+$/
ABresult
1X1
011
000
109 if 255 < length($self->$arg)
110 || $self->$arg !~ m{^[a-zA-Z0-9-_.:]+$};
111 }
112  
113 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
Pod undocumented
114 0 my $self = shift;
115 0 my ($opt, $args,) = @_;
116  
117 0 my $rf_closed = AnyEvent->condvar;
118 my $rf = Net::RabbitFoot->new(
119 verbose => $self->verbose,
120 )->load_xml_spec(
121 $self->spec,
122 )->connect(
123 0 (map {$_ => $self->$_} qw(host port user pass vhost)),
124 timeout => 5,
125 0 ▶ on_close => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
126 0 ▶ my $w; $w = AnyEvent->idle(cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
127 0 undef $w;
128 0 $self->_close(shift);
129 0 $rf_closed->send;
130 0 });
131 },
132 0 );
133  
134 0 my $ch_closed = AnyEvent->condvar;
135 my $ch = $rf->open_channel(
136 0 ▶ on_close => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
137 0 ▶ my $w; $w = AnyEvent->idle(cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 0 undef $w;
139 0 $self->_close(shift);
140 0 $ch_closed->send;
141 0 $rf->close;
142 0 });
143 },
144 0 );
145  
146 0 $self->_run($ch, @_,);
147  
148 0 $ch->close;
149 0 $rf->close;
150 0 $ch_closed->recv;
151 0 $rf_closed->recv;
152 0 return;
153 }
154  
155 0 ▶sub _close {
Subroutine _close: not called CC=1 SCAR=6.9
156 0 my $self = shift;
157 0 my $method_frame = shift->method_frame;
158 0 print $method_frame->reply_code, ' ', $method_frame->reply_text, "\n";
159 0 return;
160 }
161  
162 1 1;
163  
↑ Summary RabbitFoot/Cmd/Role/Config.pm »