lib/POE/Component/MessageQueue/Message.pm

filter: Statementstmt 65.3% 32 / 49 Branchbran 8.3% 1 / 12 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 4 totaltotal 41.2% 40 / 97 CC 13 SCAR 34.4
CC
13
Cov
44%
equals
56.0
from_stomp_frame
42.0
__ANON__
2.0
CRAP 31.1
« lib/POE/Component/MessageQueue/Storage/Default.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Memory.pm »
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 14 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 14 ▶use Net::Stomp::Frame;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 14 has id => (
23 is => 'ro',
24 isa => 'Str',
25 required => 1,
26 );
27  
28 14 has destination => (
29 is => 'ro',
30 isa => 'Str',
31 required => 1,
32 );
33  
34 14 has body => (
35 is => 'rw',
36 clearer => 'delete_body',
37 );
38  
39 14 has persistent => (
40 is => 'ro',
41 isa => 'Bool',
42 required => 1,
43 );
44  
45 14 has expire_at => (
46 is => 'rw',
47 isa => 'Num',
48 predicate => 'has_expiration',
49 );
50  
51 14 has 'deliver_at' => (
52 is => 'rw',
53 isa => 'Num',
54 predicate => 'has_delay',
55 clearer => 'clear_delay',
56 );
57  
58 14 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 67 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
72 14 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 67 return bytes::length($self->body);
74 }
75 14 );
76  
77 14 my $order = 0;
78 14 my $last_time = 0;
79  
80 has 'timestamp' => (
81 is => 'ro',
82 isa => 'Num',
83 default => sub {
84 1 ▶ my $time = time;
Subroutine __ANON__: called CC=2 SCAR=7.0
85 1 ▶ $order = 0 if $time != $last_time;
Branch: 1 branch
BranchTrueFalseTotal
if $time != $last_time 1 0 1
86 1 $last_time = $time;
87 1 return "$time." . sprintf('%05d', $order++);
88 },
89 14 );
90  
91 14 __PACKAGE__->meta->make_immutable();
92  
93 sub equals
94 {
95 0 ▶ my ($self, $other) = @_;
Subroutine equals: not called CC=7 SCAR=40.3
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 0 foreach my $name (__PACKAGE__->meta->get_attribute_list())
99 {
100 0 my $ameta = __PACKAGE__->meta->get_attribute($name);
101 0 my $reader = $ameta->get_read_method;
102 0 my ($one, $two) = ($self->$reader, $other->$reader);
103 0 ▶ next if (!defined $one) && (!defined $two);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one or defined $two 0 0 0
Condition0%0/3
defined $one or defined $two
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $one or defined $two
defined $one defined $two
Truth table0%0/3
A or B
A= defined $oneB= defined $two
ABresult
1X1
011
000
104 0 ▶ return 0 unless (defined $one) && (defined $two);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $one and defined $two 0 0 0
Condition0%0/3
defined $one and defined $two
!ll&&!rl&&r
000
MC/DC0%0/2
defined $one and defined $two
defined $one defined $two
Truth table0%0/3
A and B
A= defined $oneB= defined $two
ABresult
0X0
100
111
105 0 ▶ return 0 unless ($one eq $two);
Branch: 1 branch
BranchTrueFalseTotal
unless $one eq $two 0 0 0
106 }
107 0 return 1;
108 }
109  
110 sub clone
111 {
112 4 ▶ my $self = $_[0];
Subroutine clone: called CC=1 SCAR=0.0
Pod undocumented
113 4 return $self->meta->clone_object($self);
114 }
115  
116 sub from_stomp_frame {
117 0 ▶ my ($class, $frame) = @_;
Subroutine from_stomp_frame: not called CC=6 SCAR=37.4
Pod undocumented
118 0 ▶ my $persistent = lc($frame->headers->{persistent} || '');
Condition0%0/2
$frame->headers->{'persistent'} || ''
l!l
00
MC/DC0%0/1
$frame->headers->{'persistent'} || ''
$frame->headers->{'persistent'}
Truth table0%0/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 0 ▶ persistent => ($persistent eq 'true') || ($persistent eq '1'),
Condition0%0/3
$persistent eq 'true' || $persistent eq '1'
l!l&&r!l&&!r
000
MC/DC0%0/2
$persistent eq 'true' || $persistent eq '1'
$persistent eq 'true' $persistent eq '1'
Truth table0%0/3
A || B
A= $persistent eq 'true'B= $persistent eq '1'
ABresult
1X1
011
000
123 body => $frame->body,
124 );
125 0 ▶ 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 0 0
Condition0%0/3
not $msg->persistent and my $after = $frame->headers->{"expire-after"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $msg->persistent and my $after = $frame->headers->{"expire-after"}
not $msg->persistent my $after = $frame->headers->{"expire-after"}
Truth table0%0/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 0 ▶ if (my $after = $frame->headers->{'deliver-after'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $after = $frame->headers->{"deliver-after"}) 0 0 0
129 0 $msg->deliver_at(time + $after);
130 }
131 0 return $msg;
132 }
133  
134 sub create_stomp_frame
135 {
136 1 ▶ my $self = shift;
Subroutine create_stomp_frame: called CC=1 SCAR=0.0
Pod undocumented
137  
138 1 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 14 1;
150  
« lib/POE/Component/MessageQueue/Storage/Default.pm ↑ Summary lib/POE/Component/MessageQueue/Storage/Memory.pm »