[Jifty-commit] r1330 - jifty/trunk/lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Jun 21 06:14:04 EDT 2006


Author: dpavlin
Date: Wed Jun 21 06:13:54 2006
New Revision: 1330

Modified:
   jifty/trunk/lib/Jifty/Dispatcher.pm
   jifty/trunk/lib/Jifty/Handler.pm

Log:
Added dump_rules to dispatcher which dumps defined rules to debug log on startup

Modified: jifty/trunk/lib/Jifty/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Dispatcher.pm	(original)
+++ jifty/trunk/lib/Jifty/Dispatcher.pm	Wed Jun 21 06:13:54 2006
@@ -1190,4 +1190,59 @@
     return @matches;
 }
 
+=head2 dump_rules
+
+Dump all defined rules in debug log. It will be called by Jifty on startup.
+
+=cut
+
+sub dump_rules {
+    my $self = shift;
+
+    no strict 'refs';
+    foreach my $stage ( qw/SETUP RUN CLEANUP/ ) {
+
+        my $log = '';
+        foreach my $r ( @{ $self . '::RULES_' . $stage } ) {
+            $log .= _unroll_dumpable_rules( 0,$r );
+        }
+
+        Jifty->log->debug( "Rules in stage $stage:\n", $log) if ($log);
+    }
+};
+
+=head2 _unroll_dumpable_rules LEVEL,RULE
+
+Walk all rules defined in dispatcher starting at rule
+C<RULE> and indentation level C<LEVEL>
+
+=cut
+
+sub _unroll_dumpable_rules {
+    my ($level, $rule) = @_;
+    my $log =
+        # indentation
+        ( "    " x $level ) .
+        # op
+        ( $rule->[0] || "undef op" ) . ' ' .
+        # arguments
+        (
+            ! defined( $rule->[1] )   ? ""                                          :
+            ref $rule->[1] eq 'ARRAY' ? "'" . join("','", @{ $rule->[1] }) . "'" :
+            ref $rule->[1] eq 'HASH'  ? $rule->[1]->{method} . " '" . $rule->[1]->{""} ."'" :
+            ref $rule->[1] eq 'CODE'  ? '{...}' :
+                                        "'" . $rule->[1] . "'"
+        ) .
+        "\n";
+
+    if (ref $rule->[2] eq 'ARRAY') {
+        $level++;
+        foreach my $sr ( @{ $rule->[2] } ) {
+            $log .= _unroll_dumpable_rules( $level, $sr );
+        }
+    }
+
+    return $log;
+}
+
 1;

Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/Handler.pm	Wed Jun 21 06:13:54 2006
@@ -64,6 +64,7 @@
         Jifty->config->framework('ApplicationClass') . "::Dispatcher" );
     Jifty::Util->require( $self->dispatcher );
     $self->dispatcher->import_plugins;
+    $self->dispatcher->dump_rules;
 
     $self->mason( Jifty::View::Mason::Handler->new( $self->mason_config ) );
 


More information about the Jifty-commit mailing list