lib/Mojolicious/Plugin/UserMessages.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 9 | 9 | 100.0 |
branch | n/a | ||
condition | n/a | ||
subroutine | 4 | 4 | 100.0 |
pod | 1 | 1 | 100.0 |
total | 14 | 14 | 100.0 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Mojolicious::Plugin::UserMessages; | ||||||
2 | { | ||||||
3 | $Mojolicious::Plugin::UserMessages::VERSION = '0.511'; | ||||||
4 | } | ||||||
5 | |||||||
6 | 2 | 2 | 3207 | use Mojo::Base 'Mojolicious::Plugin'; | |||
2 | 13008 | ||||||
2 | 22 | ||||||
7 | 2 | 2 | 3330 | use Mojolicious::Plugin::UserMessages::Queue; | |||
2 | 6 | ||||||
2 | 473 | ||||||
8 | |||||||
9 | sub register { | ||||||
10 | 1 | 1 | 1 | 57 | my ($self, $app) = @_; | ||
11 | |||||||
12 | $app->helper( | ||||||
13 | 'user_messages' => sub { | ||||||
14 | 8 | 8 | 227669 | return Mojolicious::Plugin::UserMessages::Queue->new( $_[0] ); | |||
15 | 1 | 13 | }); | ||||
16 | } | ||||||
17 | |||||||
18 | =encoding UTF-8 | ||||||
19 | |||||||
20 | =head1 NAME | ||||||
21 | |||||||
22 | Mojolicious::Plugin::UserMessages - Mojolicious Plugin to manage user message queue(s) | ||||||
23 | |||||||
24 | =head1 SYNOPSIS | ||||||
25 | |||||||
26 | # Mojolicious Lite | ||||||
27 | plugin 'UserMessages' | ||||||
28 | |||||||
29 | # Mojolicious | ||||||
30 | $self->plugin('UserMessages') | ||||||
31 | |||||||
32 | # In your code add some messages to the user | ||||||
33 | $self->user_messages( info => 'Just some information' ); | ||||||
34 | $self->user_messages( success => 'Operation completed' ); | ||||||
35 | |||||||
36 | # In your template get and print the messages | ||||||
37 | # The messages will stay in the queue until you show them | ||||||
38 | # to the user | ||||||
39 | |||||||
40 | % for my $message ( user_messages->get ) { | ||||||
41 | <%= $message->type %> : <%= $message->message %> |
||||||
42 | % } | ||||||
43 | |||||||
44 | # You can also get messages from a specific type | ||||||
45 | % for my $message ( user_messages->get_info ) { | ||||||
46 | INFO : <%= $message->message %> |
||||||
47 | % } | ||||||
48 | |||||||
49 | =head1 DESCRIPTION | ||||||
50 | |||||||
51 | L |
||||||
52 | |||||||
53 | =head1 SEE ALSO | ||||||
54 | |||||||
55 | L |
||||||
56 | |||||||
57 | =head1 COPYRIGHT & LICENSE | ||||||
58 | |||||||
59 | Copyright 2013 Bruno Tavares. All right reserved. | ||||||
60 | |||||||
61 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||
62 | |||||||
63 | =cut | ||||||
64 | |||||||
65 | 1; |