line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::Growler; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3500712
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
453
|
use Dancer2::Plugin; |
|
1
|
|
|
|
|
2207
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Dancer2::Plugin::Growler::VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _growl { |
11
|
9
|
|
|
9
|
|
10552
|
my ( $dsl, $msg, $args ) = @_; |
12
|
9
|
100
|
|
|
|
154
|
$dsl->app->session->write( 'growls', [] ) if !$dsl->app->session->read('growls'); |
13
|
9
|
100
|
|
|
|
834
|
if ( exists $args->{delay} ) { |
14
|
2
|
100
|
66
|
|
|
12
|
if ( !defined $args->{delay} || $args->{delay} < 1 ) { |
15
|
1
|
|
|
|
|
3
|
$args->{allow_dismiss} = 1; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# else { |
19
|
|
|
|
|
|
|
# # ?TODO/YAGNI?: enforce a sane default if too low? |
20
|
|
|
|
|
|
|
# } |
21
|
|
|
|
|
|
|
} |
22
|
9
|
|
|
|
|
9
|
push @{ $dsl->app->session->read('growls') }, { message => $msg, options => $args }; |
|
9
|
|
|
|
|
144
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
register growl => \&_growl; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
register growl_info => sub { |
28
|
1
|
|
|
1
|
|
36
|
$_[2]->{type} = 'info'; |
29
|
1
|
|
|
|
|
2
|
goto &_growl; |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
register growl_success => sub { |
33
|
1
|
|
|
1
|
|
34
|
$_[2]->{type} = 'success'; |
34
|
1
|
|
|
|
|
3
|
goto &_growl; |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
register growl_warning => sub { |
38
|
4
|
|
|
4
|
|
133
|
$_[2]->{type} = 'warning'; |
39
|
4
|
|
|
|
|
9
|
goto &_growl; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
register growl_error => sub { |
43
|
1
|
|
|
1
|
|
33
|
$_[2]->{type} = 'danger'; |
44
|
1
|
|
|
|
|
3
|
goto &_growl; |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
register growls => sub { |
48
|
3
|
|
|
3
|
|
64937
|
my $dsl = shift; |
49
|
3
|
100
|
|
|
|
61
|
return if !$dsl->app->session->read('growls'); |
50
|
2
|
|
|
|
|
52
|
my @growls = @{ $dsl->app->session->read('growls') }; |
|
2
|
|
|
|
|
31
|
|
51
|
2
|
|
|
|
|
43
|
@{ $dsl->app->session->read('growls') } = (); |
|
2
|
|
|
|
|
29
|
|
52
|
2
|
|
|
|
|
86
|
return \@growls; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
on_plugin_import { |
56
|
|
|
|
|
|
|
my $dsl = shift; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# TODO 2: Is there a better way to add template keyword? |
59
|
|
|
|
|
|
|
$dsl->app->add_hook( |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# ?TODO/YAGNI? do growl() and growl_*() in TT also? |
62
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
63
|
|
|
|
|
|
|
name => 'before_template_render', |
64
|
|
|
|
|
|
|
code => sub { |
65
|
|
|
|
|
|
|
$_[0]->{growls} = sub { $dsl->growls(@_) } |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
) |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
}; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
register_plugin; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__END__ |