UserMessages/Queue.pm

filter: Statementstmt 82.3% 56 / 68 Branchbran 46.1% 12 / 26 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 69.0% 78 / 113 CC 17 SCAR 17.7
CC
17
Cov
71%
AUTOLOAD
9.6
has_messages_in_queue
7.5
get
6.9
CRAP 5.8
↑ Summary UserMessages/Message.pm »
1 package Mojolicious::Plugin::UserMessages::Queue;
2 {
3 2 $Mojolicious::Plugin::UserMessages::Queue::VERSION = '0.511';
4 }
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use Mojolicious::Plugin::UserMessages::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $AUTOLOAD;
12  
13 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
14 8 my ( $class, $app ) = @_;
15 8 return bless({'app'=>$app}, $class);
16 }
17  
18 8 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=22.6
19 8 my $s = shift;
20  
21 8 my $method = $AUTOLOAD;
22 8 $method =~ s/.*://; # strip fully-qualified portion
23  
24 8 ▶ return if $method eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $method eq "DESTROY" 8 0 8
25  
26 0 ▶ if ( $method =~ /^get_(.+)$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /^get_(.+)$/i) 0 0 0
27 0 my $type = lc( $1 );
28 0 return $s->get( $type );
29 }
30 0 ▶ if ( $method =~ /^has_(.+)_messages$/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /^has_(.+)_messages$/i) 0 0 0
31 0 my $type = lc( $1 );
32 0 return $s->has_messages_in_queue( $type );
33 }
34  
35 0 croak "Unkown method $method\n";
36 }
37  
38  
39 3 ▶sub add {
Subroutine add: called CC=4 SCAR=13.9
Pod undocumented
40 3 my $self = shift;
41 3 my $type = shift;
42 3 my $message = shift;
43 3 my %args = @_;
44  
45 3 my $c = $self->{'app'};
46  
47 3 ▶ if ( !$c->session->{'__ui_message_queue'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->session->{"__ui_message_queue"}) 1 2 3
48 1 $c->session->{'__ui_message_queue'} = [];
49 }
50  
51 3 ▶ return 0 if !$message;
Branch: 1 branch
BranchTrueFalseTotal
unless $message 0 3 3
52 3 ▶ return 0 if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 3 3
53  
54 3 my $msg = {
55 'type' => $type,
56 'args' => \%args,
57 'message' => $message,
58 };
59  
60 3 push @{ $c->session->{'__ui_message_queue'} }, $msg;
61  
62 3 return 1;
63 }
64  
65 2 ▶sub get {
Subroutine get: called CC=6 SCAR=19.3
Pod undocumented
66 2 my $self = shift;
67 2 my $type = shift;
68  
69 2 my $c = $self->{'app'};
70  
71 2 ▶ if ( !$c->session->{'__ui_message_queue'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->session->{"__ui_message_queue"}) 0 2 2
72 0 return [];
73 }
74  
75 2 my @to_return = ();
76 2 my @to_keep = ();
77  
78 2 for my $m ( @{ $c->session->{'__ui_message_queue'} } ) {
79 3 ▶ if ( !$type || $type eq $m->type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $type or $type eq $m->type) 3 0 3
Condition33%1/3
not $type or $type eq $m->type
l!l&&r!l&&!r
300
MC/DC0%0/2
not $type or $type eq $m->type
not $type $type eq $m->type
Truth table33%1/3
not(A) or B
A= not $typeB= $type eq $m->type
ABresult
1X1
011
000
80 3 push @to_return,
81 Mojolicious::Plugin::UserMessages::Message->new(%$m);
82 3 next;
83 }
84 0 push @to_keep, $m;
85 }
86  
87 2 $c->session->{'__ui_message_queue'} = \@to_keep;
88  
89 2 ▶ return wantarray ? @to_return : \@to_return;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
90 }
91  
92 3 ▶sub has_messages {
Subroutine has_messages: called CC=1 SCAR=0.0
Pod undocumented
93 3 my $self = shift;
94  
95 3 return $self->has_messages_in_queue();
96 }
97  
98 3 ▶sub has_messages_in_queue {
Subroutine has_messages_in_queue: called CC=6 SCAR=20.2
Pod undocumented
99 3 my $self = shift;
100 3 my $type = shift;
101  
102 3 my $c = $self->{'app'};
103 3 ▶ if ( !$c->session->{'__ui_message_queue'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->session->{"__ui_message_queue"}) 1 2 3
104 1 return 0;
105 }
106  
107 2 my @messages = @{ $c->session->{'__ui_message_queue'} };
108 2 ▶ if ( !$type ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type) 2 0 2
109 2 ▶ return scalar( @messages ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @messages ? : 2 0 2
110 }
111  
112 0 for my $m ( @messages ) {
113 0 ▶ return 1 if ( $type eq $m->{'type'} );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq $m->{"type"} 0 0 0
114 }
115  
116 0 return 0;
117 }
118  
119 2 1;
↑ Summary UserMessages/Message.pm »