/[Frey]/trunk/lib/Frey/View.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/View.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/lib/View.pm revision 10 by dpavlin, Sat Jun 28 22:13:05 2008 UTC trunk/lib/Frey/View.pm revision 53 by dpavlin, Sat Jul 5 15:19:55 2008 UTC
# Line 1  Line 1 
1  package View;  package Frey::View;
2    
3  use strict;  use strict;
4  use warnings;  use warnings;
5    
6  use Template::Declare::Tags; # defaults to 'HTML'  use Template::Declare::Tags; # defaults to 'HTML'
7  use base 'Template::Declare';  use Frey;
8    use base qw/Template::Declare/;
9  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
10    use Carp qw/carp confess/;
11    
12  template user => sub {  sub debug_dump {
13          my ( $self, $user ) = @_;          my $dump = dump( @_ );
14          p {'Hello, world wide web!'}          carp "debug_dump $dump\n";
15          pre {          pre {
16                  outs( dump( $user ) );                  { 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;  1;

Legend:
Removed from v.10  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26