X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FLog.pm;h=80e71825b9bcdcc56999cdfb0c845630672b46be;hb=f825519b38a6f50083f0507b198e34239ac674e5;hp=726ef7d4e5a3862a41314e1e11a2ecab85e3cd91;hpb=5fb12dbb7e69039e0ea22ec4d7cb627206b4508b;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm index 726ef7d..80e7182 100644 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -1,7 +1,10 @@ package Catalyst::Log; use Moose; +with 'MooseX::Emulate::Class::Accessor::Fast'; + use Data::Dump; +use Class::MOP (); our %LEVELS = (); @@ -12,6 +15,7 @@ has abort => (is => 'rw'); { my @levels = qw[ debug info warn error fatal ]; + my $meta = Class::MOP::get_metaclass_by_name(__PACKAGE__); for ( my $i = 0 ; $i < @levels ; $i++ ) { my $name = $levels[$i]; @@ -19,20 +23,18 @@ has abort => (is => 'rw'); $LEVELS{$name} = $level; - no strict 'refs'; - - *{$name} = sub { + $meta->add_method($name, sub { my $self = shift; if ( $self->level & $level ) { $self->_log( $name, @_ ); } - }; + }); - *{"is_$name"} = sub { + $meta->add_method("is_$name", sub { my $self = shift; return $self->level & $level; - }; + });; } } @@ -40,7 +42,13 @@ around new => sub { my $orig = shift; my $class = shift; my $self = $class->$orig; - $self->levels( scalar(@_) ? @_ : keys %LEVELS ); + + if (@_ == 1 && $_[0] eq 'debug') { + $self->levels( keys %LEVELS ); + } else { + $self->levels( scalar(@_) ? @_ : keys %LEVELS ); + } + return $self; }; @@ -99,6 +107,24 @@ sub _send_to_log { print STDERR @_; } +# 5.7 compat code. +# Alias _body to body, add a before modifier to warn.. +my $meta = __PACKAGE__->meta; # Calling meta method here fine as we happen at compile time. +$meta->add_method('body', $meta->get_method('_body')); +my %package_hash; # Only warn once per method, per package. + # I haven't provided a way to disable them, patches welcome. +$meta->add_before_method_modifier('body', sub { + my $class = blessed(shift); + $package_hash{$class}++ || do { + warn("Class $class is calling the deprecated method Catalyst::Log->body method,\n" + . "this will be removed in Catalyst 5.81"); + }; +}); +# End 5.70 backwards compatibility hacks. + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); + 1; __END__ @@ -237,11 +263,9 @@ over the log output. L. -=head1 AUTHOR +=head1 AUTHORS -Sebastian Riedel, C -Marcus Ramberg, C -Christian Hansen, C +Catalyst Contributors, see Catalyst.pm =head1 COPYRIGHT