7 |
use Frey; |
use Frey; |
8 |
use base qw/Template::Declare/; |
use base qw/Template::Declare/; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use Carp qw/carp/; |
use Carp qw/carp confess/; |
11 |
|
|
12 |
sub debug_dump { |
sub debug_dump { |
13 |
my $dump = dump( @_ ); |
my $dump = dump( @_ ); |
20 |
|
|
21 |
template 'status' => sub { |
template 'status' => sub { |
22 |
my ( $self ) = @_; |
my ( $self ) = @_; |
23 |
p { 'Welcome to Frey' } |
p { 'Welcome to Frey' }; |
24 |
show( 'templates' ); |
show( 'templates' ); |
25 |
show( 'classes' ); |
show( 'classes' ); |
26 |
}; |
}; |
27 |
|
|
28 |
|
sub method_link { |
29 |
|
my ( $pkg,$method ) = @_; |
30 |
|
a { |
31 |
|
{ href is "/$pkg/$method" } |
32 |
|
outs $method |
33 |
|
} |
34 |
|
} |
35 |
|
|
36 |
|
sub package_methods { |
37 |
|
my ( $pkg, $methods ) = @_; |
38 |
|
confess "methods not ARRAY ",dump($methods) unless ref($methods) =~ m/^ARRAY/; |
39 |
|
outs $pkg; |
40 |
|
ul { |
41 |
|
foreach my $method ( @{ $methods } ) { |
42 |
|
li { method_link( $pkg, $method ) } |
43 |
|
} |
44 |
|
} |
45 |
|
} |
46 |
|
|
47 |
|
template 'package-methods' => sub { |
48 |
|
my ( $self, $req, $package ) = @_; |
49 |
|
$package ||= $req->param('package'); |
50 |
|
my $templates = Template::Declare->templates->{ $package } or die "no package $package\n"; |
51 |
|
package_methods( $package, $templates ); |
52 |
|
}; |
53 |
|
|
54 |
template 'templates' => sub { |
template 'templates' => sub { |
55 |
h1 { 'Available templates' }; |
h1 { 'Available templates' }; |
56 |
my $templates = Template::Declare->templates; |
my $templates = Template::Declare->templates; |
57 |
debug_dump( $templates ); |
debug_dump( $templates ); |
58 |
|
|
59 |
ul { |
ul { |
60 |
foreach my $pkg ( keys %$templates ) { |
foreach my $package ( keys %$templates ) { |
61 |
li { |
li { |
62 |
outs $pkg; |
package_methods( $package, $templates->{$package} ); |
|
ul { |
|
|
foreach my $template ( @{ $templates->{$pkg} } ) { |
|
|
li { |
|
|
a { |
|
|
{ href is "/$pkg/$template" } |
|
|
$template |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
63 |
} |
} |
64 |
} |
} |
65 |
} |
} |
73 |
}; |
}; |
74 |
|
|
75 |
template 'error' => sub { |
template 'error' => sub { |
76 |
my $self = shift; |
my ( $self, $req, $error ) = shift; |
77 |
p { |
$error ||= dump( caller(1) ); |
78 |
|
warn "## error: $error\n"; |
79 |
|
pre { |
80 |
{ class is 'error' } |
{ class is 'error' } |
81 |
outs( @_ ); |
outs( $error ); |
82 |
} |
}; |
83 |
}; |
}; |
84 |
|
|
85 |
1; |
1; |