[Jifty-commit] r3512 -
jifty/branches/trimclient/lib/Jifty/View/Declare
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Jun 17 16:18:33 EDT 2007
Author: clkao
Date: Sun Jun 17 16:18:32 2007
New Revision: 3512
Modified:
jifty/branches/trimclient/lib/Jifty/View/Declare/Compile.pm
Log:
handle enteriter.
Modified: jifty/branches/trimclient/lib/Jifty/View/Declare/Compile.pm
==============================================================================
--- jifty/branches/trimclient/lib/Jifty/View/Declare/Compile.pm (original)
+++ jifty/branches/trimclient/lib/Jifty/View/Declare/Compile.pm Sun Jun 17 16:18:32 2007
@@ -18,6 +18,9 @@
return $ret;
}
+
+sub pp_leaveloop { shift->loop_common(@_, "") }
+
package Jifty::View::Declare::Compile;
use strict;
use base 'B::Deparse';
@@ -35,6 +38,11 @@
use constant method_invocation => '.';
+sub is_state {
+ goto \&B::Deparse::is_state;
+}
+*null = B::Deparse::null;
+
sub padname {
my $self = shift;
my $targ = shift;
@@ -54,6 +62,45 @@
return $ret;
}
+sub loop_common {
+ my $self = shift;
+ my($op, $cx, $init) = @_;
+ my $enter = $op->first;
+ my $kid = $enter->sibling;
+ if ($enter->name eq "enteriter") { # foreach
+ my $ary = $enter->first->sibling; # first was pushmark
+ my $var = $ary->sibling;
+
+ if ($ary->name eq 'null' and $enter->private & OPpITER_REVERSED) {
+ # "reverse" was optimised away
+ return $self->SUPER::loop_common(@_);
+ } elsif ($enter->flags & OPf_STACKED
+ and not null $ary->first->sibling->sibling)
+ {
+ return $self->SUPER::loop_common(@_);
+ } else {
+ $ary = $self->deparse($ary, 1);
+ }
+
+ if ($var->name ne "gv") {
+ return $self->SUPER::loop_common(@_);
+ }
+
+ $var = '$' . $self->deparse($var, 1);
+
+ my $body = $kid->first->first->sibling; # skip OP_AND and OP_ITER
+ # statement() foreach (@foo);
+ if (!is_state $body->first and $body->first->name ne "stub") {
+ Carp::confess unless $var eq '$_';
+ $body = $body->first;
+ return "$ary.each(function (\$_) {".$self->deparse($body, 2)."} )";
+ }
+ # XXX not handling cont block here yet
+ return "$ary.each(function (\$_) {".$self->deparse($body, 0)."} )";
+ }
+ return $self->SUPER::loop_common(@_);
+}
+
sub maybe_my {
my $self = shift;
my($op, $cx, $text) = @_;
More information about the Jifty-commit
mailing list