1 |
package Frey::View; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
|
6 |
use Template::Declare::Tags; # defaults to 'HTML' |
7 |
use Frey; |
8 |
use base qw/Template::Declare/; |
9 |
use Data::Dump qw/dump/; |
10 |
use Carp qw/carp confess/; |
11 |
|
12 |
sub debug_dump { |
13 |
my $dump = dump( @_ ); |
14 |
carp "debug_dump $dump\n"; |
15 |
pre { |
16 |
{ class is 'debug' } |
17 |
outs $dump; |
18 |
} |
19 |
} |
20 |
|
21 |
template 'status' => sub { |
22 |
my ( $self ) = @_; |
23 |
p { 'Welcome to Frey' }; |
24 |
show( 'templates' ); |
25 |
show( 'packages' ); |
26 |
show( 'introspect' ); |
27 |
}; |
28 |
|
29 |
sub method_link { |
30 |
my ( $pkg,$method ) = @_; |
31 |
my $url = "/$pkg/$method"; |
32 |
$url = $method if $method =~ m!^/!; |
33 |
a { |
34 |
{ href is $url } |
35 |
outs $method |
36 |
} |
37 |
} |
38 |
|
39 |
sub package_methods { |
40 |
my ( $pkg, $methods ) = @_; |
41 |
confess "methods not ARRAY ",dump($methods) unless ref($methods) =~ m/^ARRAY/; |
42 |
outs $pkg; |
43 |
ul { |
44 |
foreach my $method ( @{ $methods } ) { |
45 |
li { method_link( "crud/$pkg", $method ) } |
46 |
} |
47 |
} |
48 |
} |
49 |
|
50 |
template 'package-templates' => sub { |
51 |
my ( $self, $req, $package ) = @_; |
52 |
$package ||= $req->param('package'); |
53 |
my $methods = Template::Declare->templates->{ $package } or die "no package $package\n"; |
54 |
package_methods( $package, $methods ); |
55 |
}; |
56 |
|
57 |
template 'templates' => sub { |
58 |
h1 { 'Available templates' }; |
59 |
my $templates = Template::Declare->templates; |
60 |
debug_dump( $templates ); |
61 |
|
62 |
ul { |
63 |
foreach my $package ( keys %$templates ) { |
64 |
li { |
65 |
package_methods( $package, $templates->{$package} ); |
66 |
} |
67 |
} |
68 |
} |
69 |
}; |
70 |
|
71 |
template 'packages' => sub { |
72 |
my $self = shift; |
73 |
h1 { 'All packages in image' }; |
74 |
my $f = Frey->new; |
75 |
debug_dump( $f->classes ); |
76 |
}; |
77 |
|
78 |
use Frey::Introspect; |
79 |
|
80 |
template 'introspect' => sub { |
81 |
my $self = shift; |
82 |
h1 { 'Introspect Moose packages' }; |
83 |
ul { |
84 |
map { |
85 |
my ( $package, $path ) = each( %$_ ); |
86 |
li { |
87 |
outs $package; |
88 |
my $f = Frey::Introspect->new( package => $package ); |
89 |
my ( $class, $meta, $is_role ) = $f->load_package(); |
90 |
if ( $class->can('meta') ) { |
91 |
ul { |
92 |
foreach my $m ( $f->methods ) { |
93 |
li { method_link( $package, $m ) } |
94 |
} |
95 |
} |
96 |
pre { |
97 |
{ class is 'debug' }; |
98 |
outs $class->dump( 1 ); |
99 |
} |
100 |
} else { |
101 |
b { "not introspectable" } |
102 |
} |
103 |
} |
104 |
} @{ Frey->new->classes }; |
105 |
} |
106 |
}; |
107 |
|
108 |
template 'error' => sub { |
109 |
my ( $self, $req, $error ) = @_; |
110 |
$error ||= dump( caller(1) ); |
111 |
warn "## error: $error\n"; |
112 |
pre { |
113 |
{ class is 'error' } |
114 |
outs( $error ); |
115 |
}; |
116 |
}; |
117 |
|
118 |
1; |