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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Oct 22 21:17:04 EDT 2006


Author: audreyt
Date: Sun Oct 22 21:17:04 2006
New Revision: 2059

Modified:
   jifty/trunk/lib/Jifty/Action.pm

Log:
* Jifty::Action - add documentation for generate_auto_moniker's algorithm.

Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Sun Oct 22 21:17:04 2006
@@ -104,24 +104,6 @@
 
 =cut
 
-sub generate_auto_moniker {
-    my $self = shift;
-
-    use Digest::MD5 qw(md5_hex);
-    my $frame = 1;
-    my @stack = (ref($self) || $self);
-    while (my ($pkg, $filename, $line) = caller($frame++)) {
-        push @stack, $pkg, $filename, $line;
-    }
-
-    # Increment the per-request moniker digest counter, for the case of looped action generation
-    my $digest = md5_hex("@stack");
-    my $serial = ++(Jifty->handler->stash->{monikers}{$digest});
-    my $moniker = "auto-$digest-$serial";
-    $self->log->debug("Generating moniker $moniker from stack for $self");
-    return $moniker;
-}
-
 sub new {
     my $class = shift;
     my $self = bless {}, $class;
@@ -164,6 +146,37 @@
     return $self;
 }
 
+=head2 generate_auto_moniker 
+
+Construct an moniker for a new (or soon-to-be-constructed) action that did not have
+an explicit moniker specified.  The algorithm is simple: We snapshot the call stack,
+prefix it with the action class, and then append it with an per-request autoincrement
+counter in case the same class/stack is encountered twice, which can happen if the
+programmer placed a C<new_action> call inside a loop.
+
+The monikers generated this way is guaranteed to work across requests.
+
+=cut
+
+sub generate_auto_moniker {
+    my $self = shift;
+
+    use Digest::MD5 qw(md5_hex);
+    my $frame = 1;
+    my @stack = (ref($self) || $self);
+    while (my ($pkg, $filename, $line) = caller($frame++)) {
+        push @stack, $pkg, $filename, $line;
+    }
+
+    # Increment the per-request moniker digest counter, for the case of looped action generation
+    my $digest = md5_hex("@stack");
+    my $serial = ++(Jifty->handler->stash->{monikers}{$digest});
+    my $moniker = "auto-$digest-$serial";
+    $self->log->debug("Generating moniker $moniker from stack for $self");
+    return $moniker;
+}
+
+
 =head2 arguments
 
 B<Note>: this API is now deprecated in favour of the declarative syntax


More information about the Jifty-commit mailing list