Permalink
Browse files

some automation for DEBUG

  • Loading branch information...
1 parent d6ca4d5 commit 9562942151687df697d313e832520c0fdd697380 Zbigniew Lukasiak committed Nov 21, 2010
Showing with 22 additions and 9 deletions.
  1. +4 −0 Changes
  2. +1 −1 dist.ini
  3. +5 −2 lib/WebNano.pm
  4. +6 −2 lib/WebNano/Controller.pm
  5. +6 −4 lib/WebNano/DirController.pm
View
@@ -4,4 +4,8 @@ Revision history for WebNano
Initial release.
0.002 17-10-2010
Hiding examples from PAUSE
+0.003 2010-11-21
+ Using Class::Load
{{$NEXT}}
+ DEBUG set from env
+ some improvements in debug info
View
@@ -3,7 +3,7 @@ author = Zbigniew Lukasiak <zby@cpan.org>
license = Artistic_2_0
copyright_holder = Zbigniew Lukasiak <zby@cpan.org>
copyright_year = 2010
-version = 0.003
+version = 0.004
[@Basic]
[AutoPrereqs]
View
@@ -7,9 +7,11 @@ use WebNano::FindController 'find_nested';
use Plack::Response;
use Scalar::Util qw(blessed);
-use Object::Tiny::RW qw( renderer DEBUG );
+use Object::Tiny::RW qw( renderer );
use Encode;
+sub DEBUG { return defined( $ENV{PLACK_ENV} ) && $ENV{PLACK_ENV} eq 'development'; }
+
sub psgi_callback {
my $self = shift;
@@ -302,7 +304,8 @@ follow this rule.
=head2 DEBUG
-If set prints out some debugging information to stdout.
+If set prints out some debugging information to stdout. By default checks if
+C<$ENV{PLACK_ENV} eq 'development'>.
=head1 DIAGNOSTICS
@@ -41,8 +41,12 @@ sub local_dispatch {
}
my $method = $name . '_action';
$action = $self->can( $method ) if !$action;
- return if !$action;
- return $action->( $self, @args, @parts );
+ my $out;
+ if( $action ){
+ $out = $action->( $self, @args, @parts );
+ }
+ warn 'No local action found in "' . ref($self) . qq{" for "$name"\n} if !defined( $out ) && $self->DEBUG;
+ return $out;
}
sub handle {
@@ -18,14 +18,16 @@ sub handle {
my $path = delete $args{path};
my $self = $class->new( %args );
my $out = $self->local_dispatch( $path );
- return $out if $out;
- warn "No local action found in $class\n" if $self->DEBUG;
+ return $out if defined($out);
my( $path_part, $new_path ) = ( $path =~ qr{^([^/]*)/?(.*)} );
$path_part =~ s/::|'//g if defined( $path_part );
return if !length( $path_part );
my $controller_class = find_nested( $class->_self_path . $path_part, $args{app}->controller_search_path );
- return if !$controller_class;
- warn "Dispatching to $controller_class\n" if $self->DEBUG;
+ if( !$controller_class ){
+ warn qq{No subcontroller found in "$class" for "} . $class->_self_path . $path_part . qq{"\n} if $self->DEBUG;
+ return;
+ }
+ warn qq{Dispatching to "$controller_class"\n} if $self->DEBUG;
return $controller_class->handle(
%args,
path => $new_path,

0 comments on commit 9562942

Please sign in to comment.