X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FLog.pm;h=55570662ceec68c613dabda801334111493b632b;hb=4ac0b9cb8e9043db8a95f44af685c782bf9426e7;hp=01ff75f603a46e27b63443e34a01fa64067e3876;hpb=3cdcf968aa321182c36f5fe4f499d581f59bdeac;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Log.pm b/lib/Catalyst/Log.pm index 01ff75f..5557066 100644 --- a/lib/Catalyst/Log.pm +++ b/lib/Catalyst/Log.pm @@ -1,24 +1,21 @@ package Catalyst::Log; -use strict; -#use base 'Class::Accessor::Fast'; +use Moose; +with 'MooseX::Emulate::Class::Accessor::Fast'; + use Data::Dump; +use Class::MOP (); our %LEVELS = (); -use Moose; - has level => (is => 'rw'); -has _body => (is => 'rw'); +has _body => (is => 'rw'); has abort => (is => 'rw'); -#__PACKAGE__->mk_accessors('level'); -#__PACKAGE__->mk_accessors('body'); -#__PACKAGE__->mk_accessors('abort'); - { 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]; @@ -26,29 +23,28 @@ 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; - }; + });; } } -sub new { +around new => sub { + my $orig = shift; my $class = shift; - my $self = $class->SUPER::new; + my $self = $class->$orig; $self->levels( scalar(@_) ? @_ : keys %LEVELS ); return $self; -} +}; sub levels { my ( $self, @levels ) = @_; @@ -105,6 +101,9 @@ sub _send_to_log { print STDERR @_; } +no Moose; +__PACKAGE__->meta->make_immutable(); + 1; __END__ @@ -243,11 +242,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 @@ -256,4 +253,6 @@ it under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; + 1;