5 |
|
|
6 |
use Time::HiRes qw/time/; |
use Time::HiRes qw/time/; |
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
use Carp qw/confess/; |
use Carp qw/confess carp/; |
9 |
|
|
10 |
=head1 NAME |
=head1 NAME |
11 |
|
|
19 |
|
|
20 |
our @view_classes = qw( |
our @view_classes = qw( |
21 |
Frey::View |
Frey::View |
|
Frey::REST |
|
22 |
Strix::View |
Strix::View |
23 |
); |
); |
24 |
|
|
40 |
use Template::Declare::Tags; # defaults to 'HTML' |
use Template::Declare::Tags; # defaults to 'HTML' |
41 |
Template::Declare->init( roots => \@view_classes, around_template => sub { |
Template::Declare->init( roots => \@view_classes, around_template => sub { |
42 |
my ($orig, $path, $args, $code) = @_; |
my ($orig, $path, $args, $code) = @_; |
43 |
|
my $from = (caller(1))[3]; |
44 |
|
my $package = __PACKAGE__; |
45 |
|
if ( $from !~ m/$package/ ) { |
46 |
|
warn "SKIP around_template for $path from $from\n"; |
47 |
|
return $orig->(); |
48 |
|
} else { |
49 |
|
warn "WRAP around_temolate for $path from $from\n"; |
50 |
|
} |
51 |
|
|
52 |
my $t = time; |
my $t = time; |
53 |
html { |
html { |
54 |
head { |
head { |
55 |
title { $path } |
title { $path } |
56 |
link { |
link { |
57 |
{ rel is 'stylesheet' } |
{ rel is 'stylesheet' } |
58 |
{ href is 'static/app.css' } |
{ href is '/static/app.css' } |
59 |
{ type is 'text/css' } |
{ type is 'text/css' } |
60 |
{ media is 'screen' } |
{ media is 'screen' } |
61 |
}; |
}; |
62 |
foreach my $js ( @javascript ) { |
foreach my $js ( @javascript ) { |
63 |
script { |
script { |
64 |
{ type is 'text/javascript' } |
{ type is 'text/javascript' } |
65 |
{ src is $js } |
{ src is "/$js" } |
66 |
} |
} |
67 |
} |
}; |
68 |
} |
} |
69 |
body { |
body { |
70 |
$orig->(); |
$orig->(); |
82 |
=cut |
=cut |
83 |
|
|
84 |
sub page { |
sub page { |
85 |
my $self = shift; |
my ( $self, $page, $req, $args ) = @_; |
86 |
warn "## page $_[0]\n"; |
warn "## page $page ",dump($args),"\n"; |
87 |
return Template::Declare->show( @_ ); |
my $out = eval { Template::Declare->show( $page, $req, $args ) }; |
88 |
|
if ( $@ ) { |
89 |
|
carp "ERROR: $@"; |
90 |
|
$out = Template::Declare->show( 'error', $req, "page $page " . dump($args) . ": $@" ); |
91 |
|
} |
92 |
|
return $out; |
93 |
} |
} |
94 |
|
|
95 |
=head2 add_javascript |
=head2 add_javascript |