| 1 | package Catalyst::Plugin::LogWarnings; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use MRO::Compat; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 3 | 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 | 12 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 54 | 12 | my $c = shift; | |||||||||
| 55 | 12 | ▶ | if(eval{$c->log->can('warn')}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 12 | return do { | |||||||||
| 57 | 1 | ▶ | local $SIG{__WARN__} = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 1 | my $warning = shift; | |||||||||
| 59 | 1 | chomp $warning; | |||||||||
| 60 | 1 | $c->log->warn($warning); | |||||||||
| 61 | 12 | }; | |||||||||
| 62 | 12 | $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 | 3 | 1; # End of Catalyst::Plugin::LogWarnings | |||||||||