reapplying changes by konobi that I accidentally undid earlier. sorry about that
Guillermo Roditi [Mon, 23 Jun 2008 20:59:56 +0000 (20:59 +0000)]
r16983@martha (orig r7506):  groditi | 2008-03-15 01:21:42 -0400

lib/Catalyst/Exception.pm
lib/Catalyst/Log.pm

index ee85e1e..02610a4 100644 (file)
@@ -1,15 +1,10 @@
 package Catalyst::Exception;
 
-use strict;
-use vars qw[@ISA $CATALYST_EXCEPTION_CLASS];
-
-BEGIN {
-    push( @ISA, $CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base' );
-}
+# XXX: See bottom of file for Exception implementation
 
 package Catalyst::Exception::Base;
 
-use strict;
+use Moose;
 use Carp ();
 
 =head1 NAME
@@ -49,6 +44,10 @@ sub throw {
     Carp::croak($message);
 }
 
+=head2 meta
+
+Provided by Moose
+
 =head1 AUTHOR
 
 Sebastian Riedel, C<sri@cpan.org>
@@ -61,4 +60,13 @@ it under the same terms as Perl itself.
 
 =cut
 
+package Catalyst::Exception;
+
+use Moose;
+use vars qw[$CATALYST_EXCEPTION_CLASS];
+
+BEGIN {
+    extends($CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base');
+}
+
 1;
index 822ea32..01ff75f 100644 (file)
@@ -1,14 +1,20 @@
 package Catalyst::Log;
 
 use strict;
-use base 'Class::Accessor::Fast';
+#use base 'Class::Accessor::Fast';
 use Data::Dump;
 
 our %LEVELS = ();
 
-__PACKAGE__->mk_accessors('level');
-__PACKAGE__->mk_accessors('body');
-__PACKAGE__->mk_accessors('abort');
+use Moose;
+
+has level => (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 ];
@@ -25,14 +31,14 @@ __PACKAGE__->mk_accessors('abort');
         *{$name} = sub {
             my $self = shift;
 
-            if ( $self->{level} & $level ) {
+            if ( $self->level & $level ) {
                 $self->_log( $name, @_ );
             }
         };
 
         *{"is_$name"} = sub {
             my $self = shift;
-            return $self->{level} & $level;
+            return $self->level & $level;
         };
     }
 }
@@ -52,12 +58,20 @@ sub levels {
 
 sub enable {
     my ( $self, @levels ) = @_;
-    $self->{level} |= $_ for map { $LEVELS{$_} } @levels;
+    my $level = $self->level;
+    for(map { $LEVELS{$_} } @levels){
+      $level |= $_;
+    }
+    $self->level($level);
 }
 
 sub disable {
     my ( $self, @levels ) = @_;
-    $self->{level} &= ~$_ for map { $LEVELS{$_} } @levels;
+    my $level = $self->level;
+    for(map { $LEVELS{$_} } @levels){
+      $level &= ~$_;
+    }
+    $self->level($level);
 }
 
 sub _dump {
@@ -70,18 +84,20 @@ sub _log {
     my $level   = shift;
     my $message = join( "\n", @_ );
     $message .= "\n" unless $message =~ /\n$/;
-    $self->{body} .= sprintf( "[%s] %s", $level, $message );
+    my $body = $self->_body;
+    $body .= sprintf( "[%s] %s", $level, $message );
+    $self->_body($body);
 }
 
 sub _flush {
     my $self = shift;
-    if ( $self->abort || !$self->body ) {
+    if ( $self->abort || !$self->_body ) {
         $self->abort(undef);
     }
     else {
-        $self->_send_to_log( $self->body );
+        $self->_send_to_log( $self->_body );
     }
-    $self->body(undef);
+    $self->_body(undef);
 }
 
 sub _send_to_log {
@@ -169,6 +185,10 @@ arguments.
     $log = Catalyst::Log->new;
     $log = Catalyst::Log->new( 'warn', 'error' );
 
+=head2 level
+
+Contains a bitmask of the currently set log levels.
+
 =head2 levels
 
 Set log levels
@@ -217,6 +237,8 @@ This protected method is what actually sends the log information to STDERR.
 You may subclass this module and override this method to get finer control
 over the log output.
 
+=head2 meta
+
 =head1 SEE ALSO
 
 L<Catalyst>.