line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::LogWarnings; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
49008
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
74
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
5
|
2
|
|
|
2
|
|
2844
|
use MRO::Compat; |
|
2
|
|
|
|
|
7684
|
|
|
2
|
|
|
|
|
364
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Catalyst::Plugin::LogWarnings - Log perl warnings to your Catalyst log object |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.03 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
In MyApp.pm: |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Catalyst qw/LogWarnings/; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
After that, any C<warn> statement that's executed during action |
26
|
|
|
|
|
|
|
processing is sent to the log C<$c->log> as a warning (instead of |
27
|
|
|
|
|
|
|
being dumped to STDERR). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Example: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
package MyApp::Controller::Foo; |
32
|
|
|
|
|
|
|
sub foo : Local() { warn 'foobar!'; } |
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Output (if you're using the standard Catalyst::Log logger): |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
[info] MyApp running on Catalyst 5.7001 |
38
|
|
|
|
|
|
|
[warn] foobar at Foo.pm line 2 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 CONFIGURATION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
None. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 OVERRIDES |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 execute |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Wraps C<Catalyst::execute> and catches warnings with a |
49
|
|
|
|
|
|
|
C<$SIG{__WARN__}> statement. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub execute { |
54
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
55
|
0
|
0
|
|
|
|
|
if(eval{$c->log->can('warn')}){ |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return do { |
57
|
|
|
|
|
|
|
local $SIG{__WARN__} = sub { |
58
|
0
|
|
|
0
|
|
|
my $warning = shift; |
59
|
0
|
|
|
|
|
|
chomp $warning; |
60
|
0
|
|
|
|
|
|
$c->log->warn($warning); |
61
|
0
|
|
|
|
|
|
}; |
62
|
0
|
|
|
|
|
|
$c->next::method(@_); |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
|
|
|
|
|
|
# warn "Can't log warnings"; |
67
|
|
|
|
|
|
|
# if we can't log warnings, don't catch them |
68
|
0
|
|
|
|
|
|
return $c->next::method(@_); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 AUTHOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Jonathan Rockway, C<< <jrockway at cpan.org> >> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 BUGS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Warnings are caught after perl's rewritten them, so the line number |
79
|
|
|
|
|
|
|
and filename will be tacked on. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
82
|
|
|
|
|
|
|
C<bug-catalyst-plugin-logwarnings at rt.cpan.org>, or through the web interface at |
83
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-LogWarnings>. |
84
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
85
|
|
|
|
|
|
|
your bug as I make changes. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 SUPPORT |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
perldoc Catalyst::Plugin::LogWarnings |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
You can also look for information at: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item * Catalyst Project Homepage |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L<http://www.catalystframework.org/> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Catalyst-Plugin-LogWarnings> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * CPAN Ratings |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Catalyst-Plugin-LogWarnings> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-LogWarnings> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item * Search CPAN |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Catalyst-Plugin-LogWarnings> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=back |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#catalyst (L<irc://irc.perl.org/#catalyst>). |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Copyright 2006 Jonathan Rockway, all rights reserved. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
128
|
|
|
|
|
|
|
under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; # End of Catalyst::Plugin::LogWarnings |