42 |
our @javascript; |
our @javascript; |
43 |
our $debug = 0; |
our $debug = 0; |
44 |
|
|
45 |
Template::Declare->init( roots => \@view_classes, around_template => sub { |
Template::Declare->init( roots => \@view_classes ); |
46 |
my ($orig, $path, $args, $code) = @_; |
sub page_template { |
47 |
my $from = (caller(1))[3]; |
my ( $body ) = @_; |
48 |
my $package = __PACKAGE__; |
my $title = (caller(0))[3]; |
|
if ( $from !~ m/$package/ ) { |
|
|
warn "SKIP around_template for $path from $from\n"; |
|
|
return $orig->(); |
|
|
} else { |
|
|
warn "WRAP around_temolate for $path from $from\n"; |
|
|
} |
|
49 |
|
|
50 |
my $t = time; |
my $t = time; |
51 |
html { |
html { |
52 |
head { |
head { |
53 |
title { $path } |
title { $title } |
54 |
link { |
link { |
55 |
{ rel is 'stylesheet' } |
{ rel is 'stylesheet' } |
56 |
{ href is '/static/app.css' } |
{ href is '/static/app.css' } |
64 |
} |
} |
65 |
}; |
}; |
66 |
} |
} |
67 |
body { |
body { outs_raw $body } |
|
$orig->(); |
|
|
} |
|
68 |
}; |
}; |
69 |
warn "TEMPLATE $path ",dump($args),sprintf(" in %.4fs\n",time - $t) if $debug; |
}; |
|
}); |
|
70 |
|
|
71 |
=head2 page |
=head2 page |
72 |
|
|
80 |
my ( $self, $page, $req, $args ) = @_; |
my ( $self, $page, $req, $args ) = @_; |
81 |
warn "## buffer_stack ",dump( Template::Declare->buffer_stack ); |
warn "## buffer_stack ",dump( Template::Declare->buffer_stack ); |
82 |
Template::Declare->buffer->clear; # XXX we need to manually do this! |
Template::Declare->buffer->clear; # XXX we need to manually do this! |
|
warn "## page $page ",dump($args),"\n"; |
|
83 |
my $out = eval { Template::Declare->show( $page, $req, $args ) }; |
my $out = eval { Template::Declare->show( $page, $req, $args ) }; |
84 |
if ( $@ ) { |
if ( $@ ) { |
85 |
carp "ERROR: $@"; |
carp "ERROR: $@"; |
86 |
$out = Template::Declare->show( 'error', $req, "page $page " . dump($args) . ": $@" ); |
$out = Template::Declare->show( 'error', $req, "page $page " . dump($args) . ": $@" ); |
87 |
} |
} |
88 |
return $out; |
warn "## page $page ",dump($args)," ",length($out)," bytes\n"; |
89 |
|
return scalar page_template($out); |
90 |
} |
} |
91 |
|
|
92 |
=head2 add_javascript |
=head2 add_javascript |