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];
$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 ) = @_;
print STDERR @_;
}
+no Moose;
+__PACKAGE__->meta->make_immutable();
+
1;
__END__
L<Catalyst>.
-=head1 AUTHOR
+=head1 AUTHORS
-Sebastian Riedel, C<sri@cpan.org>
-Marcus Ramberg, C<mramberg@cpan.org>
-Christian Hansen, C<ch@ngmedia.com>
+Catalyst Contributors, see Catalyst.pm
=head1 COPYRIGHT
=cut
+__PACKAGE__->meta->make_immutable;
+
1;