| 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
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if ( $method =~ /^get_(.+)$/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | my $type = lc( $1 ); | |||||||||||||||||||||||||||
| 28 | 0 | return $s->get( $type ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ( $method =~ /^has_(.+)_messages$/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 48 | 1 | $c->session->{'__ui_message_queue'} = []; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | return 0 if !$message; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | return 0 if !$type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
not $type or $type eq $m->type
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 104 | 1 | return 0; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | my @messages = @{ $c->session->{'__ui_message_queue'} }; | |||||||||||||||||||||||||||
| 108 | 2 | ▶ | if ( !$type ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 2 | ▶ | return scalar( @messages ) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | for my $m ( @messages ) { | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | return 1 if ( $type eq $m->{'type'} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | return 0; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 2 | 1; | |||||||||||||||||||||||||||