| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojolicious::Plugin::Notifications::HTML; | 
| 2 | 8 |  |  | 8 |  | 5497 | use Mojo::Base 'Mojolicious::Plugin::Notifications::Engine'; | 
|  | 8 |  |  |  |  | 59 |  | 
|  | 8 |  |  |  |  | 67 |  | 
| 3 | 8 |  |  | 8 |  | 882 | use Exporter 'import'; | 
|  | 8 |  |  |  |  | 16 |  | 
|  | 8 |  |  |  |  | 313 |  | 
| 4 | 8 |  |  | 8 |  | 45 | use Mojo::Util qw/xml_escape/; | 
|  | 8 |  |  |  |  | 20 |  | 
|  | 8 |  |  |  |  | 399 |  | 
| 5 | 8 |  |  | 8 |  | 68 | use Scalar::Util qw/blessed/; | 
|  | 8 |  |  |  |  | 17 |  | 
|  | 8 |  |  |  |  | 350 |  | 
| 6 | 8 |  |  | 8 |  | 52 | use Mojo::ByteStream 'b'; | 
|  | 8 |  |  |  |  | 18 |  | 
|  | 8 |  |  |  |  | 4208 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our @EXPORT_OK = ('notify_html'); | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # TODO: | 
| 11 |  |  |  |  |  |  | #   Make the form have a class instead of the button! | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # TODO: | 
| 14 |  |  |  |  |  |  | #   Maybe make the buttons be part of a single form. | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # TODO: | 
| 17 |  |  |  |  |  |  | #   Add a redirect URL with ClosedRedirect, so it's ensured | 
| 18 |  |  |  |  |  |  | #   a redirect won't be misused. | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # Exportable function | 
| 21 |  |  |  |  |  |  | sub notify_html { | 
| 22 | 54 | 100 | 66 | 54 | 1 | 2718 | my $c = shift if blessed $_[0] && $_[0]->isa('Mojolicious::Controller'); | 
| 23 | 54 |  |  |  |  | 130 | my $type = shift; | 
| 24 | 54 | 100 | 100 |  |  | 224 | my $param = shift if ref $_[0] && ref $_[0] eq 'HASH'; | 
| 25 | 54 |  |  |  |  | 111 | my $msg = pop; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 54 |  |  |  |  | 141 | my $str = qq{ };  | 
| 28 | 54 | 100 | 66 |  |  | 395 | $str .= blessed $msg && $msg->isa('Mojo::ByteStream') ? $msg : xml_escape($msg); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # Check for confirmation | 
| 31 | 54 | 100 |  |  |  | 832 | if ($param) { | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Okay path is defined | 
| 34 | 27 | 100 |  |  |  | 89 | if ($param->{ok}) { | 
| 35 | 10 |  |  |  |  | 65 | $str .= ' | 
| 36 | 10 | 100 |  |  |  | 1722 | $str .= $c->csrf_field if $c; | 
| 37 | 10 |  | 100 |  |  | 1506 | $str .= ''; | 
| 38 | 10 |  |  |  |  | 22 | $str .= ''; | 
| 39 |  |  |  |  |  |  | }; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | # Cancel path is defined | 
| 42 | 27 | 100 |  |  |  | 80 | if ($param->{cancel}) { | 
| 43 | 10 |  |  |  |  | 72 | $str .= ' | 
| 44 | 10 | 50 |  |  |  | 1726 | $str .= $c->csrf_field if $c; | 
| 45 | 10 |  | 100 |  |  | 1544 | $str .= ''; | 
| 46 | 10 |  |  |  |  | 25 | $str .= ''; | 
| 47 |  |  |  |  |  |  | }; | 
| 48 |  |  |  |  |  |  | }; | 
| 49 | 54 |  |  |  |  | 256 | return $str . "\n"; | 
| 50 |  |  |  |  |  |  | }; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Notification method | 
| 54 |  |  |  |  |  |  | sub notifications { | 
| 55 | 12 |  |  | 12 | 1 | 38 | my ($self, $c, $notify_array) = @_; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 12 |  |  |  |  | 53 | my $html = ''; | 
| 58 | 12 |  |  |  |  | 35 | foreach (@$notify_array) { | 
| 59 | 21 |  |  |  |  | 42 | $html .= notify_html($c, @{$_}); | 
|  | 21 |  |  |  |  | 76 |  | 
| 60 |  |  |  |  |  |  | }; | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 12 |  |  |  |  | 140 | return b($html); | 
| 63 |  |  |  |  |  |  | }; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | 1; | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | __END__ |