[Jifty-commit] r3628 - in jifty/branches/trimclient: . lib/Jifty/View/Declare

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Jul 9 10:56:47 EDT 2007


Author: clkao
Date: Mon Jul  9 10:56:46 2007
New Revision: 3628

Modified:
   jifty/branches/trimclient/Makefile.PL
   jifty/branches/trimclient/lib/Jifty/View/Declare/BaseClass.pm
   jifty/branches/trimclient/lib/Jifty/View/Declare/Compile.pm
   jifty/branches/trimclient/lib/Jifty/Web/PageRegion.pm

Log:
Make trimclient disabled rather than fatal when new B::Deparse isn't there.

Modified: jifty/branches/trimclient/Makefile.PL
==============================================================================
--- jifty/branches/trimclient/Makefile.PL	(original)
+++ jifty/branches/trimclient/Makefile.PL	Mon Jul  9 10:56:46 2007
@@ -56,6 +56,7 @@
 requires('Module::Refresh');
 requires('Module::ScanDeps');
 requires('Object::Declare' => '0.13');
+requires('PadWalker');
 requires('Params::Validate');
 requires('Scalar::Defer' => '0.10');
 requires('Shell::Command');

Modified: jifty/branches/trimclient/lib/Jifty/View/Declare/BaseClass.pm
==============================================================================
--- jifty/branches/trimclient/lib/Jifty/View/Declare/BaseClass.pm	(original)
+++ jifty/branches/trimclient/lib/Jifty/View/Declare/BaseClass.pm	Mon Jul  9 10:56:46 2007
@@ -5,7 +5,7 @@
 use base qw/Exporter Jifty::View::Declare::Helpers/;
 use Scalar::Defer;
 use Template::Declare::Tags;
-
+use PadWalker;
 
 use Jifty::View::Declare::Helpers;
 
@@ -54,17 +54,41 @@
     }
 }
 
+sub _actual_td_code {
+    my $class = shift;
+    my $path = shift;
+    my $code = Template::Declare->resolve_template($path) or return;
+    my $closed_over = PadWalker::closed_over($code)->{'$coderef'};
+    return $closed_over ? $$closed_over : $code;
+}
+
 use Attribute::Handlers;
-our %Static;
+my (%Static, %Action);
 sub Static :ATTR(CODE,BEGIN) {
     $Static{$_[2]}++;
 }
 
-our %Action;
 sub Action :ATTR(CODE,BEGIN) {
     $Action{$_[2]}++;
 }
 
+=head2 client_cacheable
+
+Returns the type of cacheable object for client
+
+=cut
+
+sub client_cacheable {
+    my $self = shift;
+    my $path = shift;
+    my $code = $self->_actual_td_code($path) or return;
+
+    return 'static' if $Static{$code};
+    return 'action' if $Action{$code};
+    return;
+}
+
+
 =head2 show templatename arguments
 
 Render a C<Template::Declare> template.

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	Mon Jul  9 10:56:46 2007
@@ -201,4 +201,10 @@
     $self->SUPER::walk_lineseq($op, $kids, $callback);
 }
 
+sub compile_to_js {
+    my $class = shift;
+    my $code = shift;
+    return 'function() '.$class->new->coderef2text($code);
+}
+
 1;

Modified: jifty/branches/trimclient/lib/Jifty/Web/PageRegion.pm
==============================================================================
--- jifty/branches/trimclient/lib/Jifty/Web/PageRegion.pm	(original)
+++ jifty/branches/trimclient/lib/Jifty/Web/PageRegion.pm	Mon Jul  9 10:56:46 2007
@@ -384,57 +384,30 @@
     return "#region-" . $self->qualified_name . ' ' . join(' ', @_);
 }
 
-use PadWalker;
-use Jifty::View::Declare::Compile;
+my $can_compile = eval 'use Jifty::View::Declare::Compile; 1' ? 1 : 0;
 
-sub _actual_td_code {
-    my $code = shift or return;
-    my $closed_over = PadWalker::closed_over($code)->{'$coderef'};
-    return $closed_over ? $$closed_over : $code;
-}
+=head2 client_cacheable
+
+=cut
 
 sub client_cacheable {
     my $self = shift;
-    return 'crudview' if $self->path eq '//todo/view';
-    my $code = _actual_td_code(Template::Declare->resolve_template($self->path));
-
-    return 'static' if $Jifty::View::Declare::BaseClass::Static{$code};
-    return 'action' if $Jifty::View::Declare::BaseClass::Action{$code};
+    return unless $can_compile;
 
-    return;
+    return Jifty::View::Declare::BaseClass->client_cacheable($self->path);
 }
 
-sub client_cache_content {
-    my $self = shift;
-    my $code = _actual_td_code(Template::Declare->resolve_template($self->path));
-
-    if ($Jifty::View::Declare::BaseClass::Static{$code}) {
-	return 'function() '.Jifty::View::Declare::Compile->new->coderef2text($code);
-    }
-    if ($Jifty::View::Declare::BaseClass::Action{$code}) {
-	return 'function() '.Jifty::View::Declare::Compile->new->coderef2text($code);
-    }
-
-    local @Evil::ISA = ('Yada::Model::Todo');
-    local $HTML::Mason::Commands::m = undef;
-    local Jifty->handler->apache->{http_header_sent} = 1;
-
-    # dup from JV::Declare::Handler
-    no warnings qw/redefine/;
-    local *Jifty::Web::out = sub {
-        shift;    # Turn the method into a function
-        goto &Template::Declare::Tags::outs_raw;
-    };
-
-    return Template::Declare::Tags::show_page( $self->path, (bless {}, 'Evil') );
-}
+=head2 client_cacheable
 
-package Evil;
+=cut
 
-sub id { return '${id}' }
+sub client_cache_content {
+    my $self = shift;
+    return unless $can_compile;
 
-sub _value {
-    return '${'.$_[1].'}';
+    return Jifty::View::Declare::Compile->compile_to_js(
+        Jifty::View::Declare::BaseClass->_actual_td_code($self->path)
+    );
 }
 
 1;


More information about the Jifty-commit mailing list