line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer2::Plugin::Growler; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
452248
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
704
|
use Dancer2::Plugin; |
|
1
|
|
|
|
|
2120
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$Dancer2::Plugin::Growler::VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub _growl { |
11
|
9
|
|
|
9
|
|
9645
|
my ( $dsl, $msg, $args ) = @_; |
12
|
9
|
100
|
|
|
|
173
|
$dsl->app->session->write( 'growls', [] ) if !$dsl->app->session->read('growls'); |
13
|
9
|
100
|
|
|
|
810
|
if ( exists $args->{delay} ) { |
14
|
2
|
100
|
66
|
|
|
13
|
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
|
|
|
|
|
10
|
push @{ $dsl->app->session->read('growls') }, { message => $msg, options => $args }; |
|
9
|
|
|
|
|
640
|
|
23
|
9
|
|
|
|
|
397
|
$dsl->app->session->write( 'growls', $dsl->app->session->read('growls') ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
register growl => \&_growl; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
register growl_info => sub { |
29
|
1
|
|
|
1
|
|
110
|
$_[2]->{type} = 'info'; |
30
|
1
|
|
|
|
|
3
|
goto &_growl; |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
register growl_success => sub { |
34
|
1
|
|
|
1
|
|
108
|
$_[2]->{type} = 'success'; |
35
|
1
|
|
|
|
|
3
|
goto &_growl; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
register growl_warning => sub { |
39
|
4
|
|
|
4
|
|
435
|
$_[2]->{type} = 'warning'; |
40
|
4
|
|
|
|
|
9
|
goto &_growl; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
register growl_error => sub { |
44
|
1
|
|
|
1
|
|
108
|
$_[2]->{type} = 'danger'; |
45
|
1
|
|
|
|
|
3
|
goto &_growl; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
register growls => sub { |
49
|
3
|
|
|
3
|
|
34748
|
my $dsl = shift; |
50
|
3
|
100
|
|
|
|
50
|
return if !$dsl->app->session->read('growls'); |
51
|
2
|
|
|
|
|
59
|
my @growls = @{ $dsl->app->session->read('growls') }; |
|
2
|
|
|
|
|
36
|
|
52
|
2
|
|
|
|
|
90
|
$dsl->app->session->write( 'growls', [] ); |
53
|
2
|
|
|
|
|
190
|
return \@growls; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
on_plugin_import { |
57
|
|
|
|
|
|
|
my $dsl = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# TODO 2: Is there a better way to add template keyword? |
60
|
|
|
|
|
|
|
$dsl->app->add_hook( |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# ?TODO/YAGNI? do growl() and growl_*() in TT also? |
63
|
|
|
|
|
|
|
Dancer2::Core::Hook->new( |
64
|
|
|
|
|
|
|
name => 'before_template_render', |
65
|
|
|
|
|
|
|
code => sub { |
66
|
|
|
|
|
|
|
$_[0]->{growls} = sub { $dsl->growls(@_) } |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
) |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
register_plugin; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |