lib/POE/Component/MessageQueue/Message.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 66.6% 8 / 12 Conditioncond 42.8% 6 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 73.2% 71 / 97 CC 13 SCAR 17.4
CC
13
Cov
81%
from_stomp_frame
9.3
equals
7.7
__ANON__
2.0
CRAP 5.7
« lib/POE/Component/MessageQueue/Statistics.pm ↑ Summary script/mq.pl »
1 #
2 # Copyright 2007-2010 David Snopek <dsnopek@gmail.com>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
17  
18 package POE::Component::MessageQueue::Message;
19 18 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use Net::Stomp::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 18 has id => (
23 is => 'ro',
24 isa => 'Str',
25 required => 1,
26 );
27  
28 18 has destination => (
29 is => 'ro',
30 isa => 'Str',
31 required => 1,
32 );
33  
34 18 has body => (
35 is => 'rw',
36 clearer => 'delete_body',
37 );
38  
39 18 has persistent => (
40 is => 'ro',
41 isa => 'Bool',
42 required => 1,
43 );
44  
45 18 has expire_at => (
46 is => 'rw',
47 isa => 'Num',
48 predicate => 'has_expiration',
49 );
50  
51 18 has 'deliver_at' => (
52 is => 'rw',
53 isa => 'Num',
54 predicate => 'has_delay',
55 clearer => 'clear_delay',
56 );
57  
58 18 has claimant => (
59 is => 'rw',
60 isa => 'Maybe[Int]',
61 writer => 'claim',
62 predicate => 'claimed',
63 clearer => 'disown',
64 );
65  
66 has 'size' => (
67 is => 'ro',
68 isa => 'Num',
69 lazy => 1,
70 default => sub {
71 620 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
72 18 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 620 return bytes::length($self->body);
74 }
75 18 );
76  
77 18 my $order = 0;
78 18 my $last_time = 0;
79  
80 has 'timestamp' => (
81 is => 'ro',
82 isa => 'Num',
83 default => sub {
84 151 ▶ my $time = time;
Subroutine __ANON__: called CC=2 SCAR=6.9
85 151 ▶ $order = 0 if $time != $last_time;
Branch: 1 branch
BranchTrueFalseTotal
if $time != $last_time 6 145 151
86 151 $last_time = $time;
87 151 return "$time." . sprintf('%05d', $order++);
88 },
89 18 );
90  
91 18 __PACKAGE__->meta->make_immutable();
92  
93 sub equals
94 {
95 1414 ▶ my ($self, $other) = @_;
Subroutine equals: called CC=7 SCAR=20.4
Pod undocumented
96 # This is a dirty hack, rewriting to use get_attribute_list would be preferred
97 #foreach my $ameta (values %{__PACKAGE__->meta->_attribute_map})
98 1414 foreach my $name (__PACKAGE__->meta->get_attribute_list())
99 {
100 12726 my $ameta = __PACKAGE__->meta->get_attribute($name);
101 12726 my $reader = $ameta->get_read_method;
102 12726 my ($one, $two) = ($self->$reader, $other->$reader);
103 12726 ▶ next if (!defined $one) && (!defined $two);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one or defined $two 4242 8484 12726
Condition66%2/3
defined $one or defined $two
l!l&&r!l&&!r
848404242
MC/DC50%1/2
defined $one or defined $two
defined $one defined $two
Truth table66%2/3
A or B
A= defined $oneB= defined $two
ABresult
1X1
011
000
104 8484 ▶ return 0 unless (defined $one) && (defined $two);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one and defined $two 0 8484 8484
Condition33%1/3
defined $one and defined $two
!ll&&!rl&&r
008484
MC/DC0%0/2
defined $one and defined $two
defined $one defined $two
Truth table33%1/3
A and B
A= defined $oneB= defined $two
ABresult
0X0
100
111
105 8484 ▶ return 0 unless ($one eq $two);
Branch: 1 branch
BranchTrueFalseTotal
unless $one eq $two 0 8484 8484
106 }
107 1414 return 1;
108 }
109  
110 sub clone
111 {
112 2101 ▶ my $self = $_[0];
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
113 2101 return $self->meta->clone_object($self);
114 }
115  
116 sub from_stomp_frame {
117 150 ▶ my ($class, $frame) = @_;
Subroutine from_stomp_frame: called CC=6 SCAR=22.3
Pod undocumented
118 150 ▶ my $persistent = lc($frame->headers->{persistent} || '');
Condition50%1/2
$frame->headers->{'persistent'} || ''
l!l
1500
MC/DC0%0/1
$frame->headers->{'persistent'} || ''
$frame->headers->{'persistent'}
Truth table50%1/2
A
A= $frame->headers->{'persistent'}
Aresult
11
00
119 my $msg = $class->new(
120 id => $frame->headers->{'message-id'},
121 destination => $frame->headers->{destination},
122 150 ▶ persistent => ($persistent eq 'true') || ($persistent eq '1'),
Condition33%1/3
$persistent eq 'true' || $persistent eq '1'
l!l&&r!l&&!r
15000
MC/DC0%0/2
$persistent eq 'true' || $persistent eq '1'
$persistent eq 'true' $persistent eq '1'
Truth table33%1/3
A || B
A= $persistent eq 'true'B= $persistent eq '1'
ABresult
1X1
011
000
123 body => $frame->body,
124 );
125 150 ▶ if (!$msg->persistent and my $after = $frame->headers->{'expire-after'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $msg->persistent and my $after = $frame->headers->{"expire-after"}) 0 150 150
Condition33%1/3
not $msg->persistent and my $after = $frame->headers->{"expire-after"}
!ll&&!rl&&r
15000
MC/DC0%0/2
not $msg->persistent and my $after = $frame->headers->{"expire-after"}
not $msg->persistent my $after = $frame->headers->{"expire-after"}
Truth table33%1/3
not(A) and B
A= not $msg->persistentB= my $after = $frame->headers->{"expire-after"}
ABresult
0X0
100
111
126 0 $msg->expire_at(time + $after);
127 }
128 150 ▶ if (my $after = $frame->headers->{'deliver-after'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $after = $frame->headers->{"deliver-after"}) 0 150 150
129 0 $msg->deliver_at(time + $after);
130 }
131 150 return $msg;
132 }
133  
134 sub create_stomp_frame
135 {
136 131 ▶ my $self = shift;
Subroutine create_stomp_frame: called CC=1 SCAR=0.0
Pod undocumented
137  
138 131 return Net::Stomp::Frame->new({
139 command => 'MESSAGE',
140 headers => {
141 'destination' => $self->destination,
142 'message-id' => $self->id,
143 'content-length' => $self->size,
144 },
145 body => $self->body,
146 });
147 }
148  
149 18 1;
150  
« lib/POE/Component/MessageQueue/Statistics.pm ↑ Summary script/mq.pl »