/[Frey]/trunk/lib/Frey/Class/Browser.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/Class/Browser.pm

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

trunk/lib/Frey/ClassBrowser.pm revision 213 by dpavlin, Fri Oct 31 19:51:51 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 1133 by dpavlin, Tue Jun 30 15:10:55 2009 UTC
# Line 1  Line 1 
1  package Frey::ClassBrowser;  package Frey::Class::Browser;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  use lib 'lib';
 with 'Frey::Web';  
5    
6  use Frey::ClassLoader;  extends 'Frey::Class::Loader';
7    with 'Frey::Web', 'Frey::Session', 'Frey::Web::CombineImages', 'Frey::Class::Icon';
8    
9  our $markup;  use Data::Dump qw/dump/;
10    
11  sub markup {  has 'usage_sort' => (
12          return $markup if $markup;          is => 'rw',
13          my $f = Frey::ClassLoader->new;          isa => 'Bool',
14          my $html;          default => 0,
15          foreach my $package ( $f->classes ) {          documentation => 'Sort by class usage',
16                  $html .= qq|<tr><td><a href="/~/$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;  );
17                  if ( $package->can('meta') ) {  
18                          if ( $package->meta->isa('Moose::Meta::Role') ) {  has 'usage_on_top' => (
19            is => 'rw',
20            isa => 'Bool',
21            default => 1,
22            documentation => 'Show usage on top of list',
23    );
24    
25    our $usage;
26    
27    sub as_markup {
28            my $self = shift;
29            my $row;
30            my @icons;
31    
32            $usage ||= $self->session_dump( $self->usage );
33            #warn "# usage ",dump( $usage );
34    
35            my $runnable = $self->load('var/Frey/Class/Browser/runnable.yaml');
36    
37            foreach my $class ( $self->classes ) {
38    
39                    my $icon = $self->icon_path( $class );
40    
41                    if ($icon) {
42                            push @icons, $icon;
43                            $icon = qq|<!-- icon:$icon -->|;
44                    } else {
45                            $icon = '';
46                    }
47    
48                    my $html
49                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
50                            . $self->class_path( $class )
51                            . qq|">$class</a>
52                            <a target="Frey::Class::Graph" title="show class graph" href="/Frey::Class::Graph/as_markup?filter=$class&filter_class=1&filter_extends=0&filter_includes=0&filter_roles=0&show_extends=1&show_includes=1&show_roles=1&layout=dot" class="graph">&#x260D;</a>
53                            </td><td>|
54                            ;
55                    if ( $class->can('meta') ) {
56                            if ( $class->meta->isa('Moose::Meta::Role') ) {
57                                  $html .= qq|role|;                                  $html .= qq|role|;
58                          } else {                          } else {
59                                  $html .= qq|<a href="/od/$package">design</a>| if $package->can('collection');                                  $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
60                          }                          }
61                  }                  }
62                  my @inspect;  
63                  push @inspect, qq|<a href="/ob/$package">collection</a>| if $package->can('collection_table');                  my @runnable = ();
64                  push @inspect, qq|<a href="/markup/$package">markup</a>| if $package->can('markup');                  @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class }; # FIXME needs review
65                  push @inspect, qq|<a href="/request/$package">request</a>| if $package->can('request');                  @runnable = $self->class_runnable( $class ) unless @runnable;
66                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;  
67                    my @run = map {
68                            my $invoke = $_;
69                            s{^as_}{};
70                            s{_as_\w+}{};
71                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
72                    } @runnable;
73                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
74    
75                    my @inputs = $self->class_inputs( $class );
76    
77                    $usage->{$class} ||= 0;
78                    $html
79                            .= qq|</td><td>|
80                            . join(' ', @run)
81                            . qq|</td><td>|
82                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
83                            . qq|</td><td>|
84                            . ( $usage->{$class} || '' )
85                            . qq|</td></tr>|
86                            ;
87                    $row->{$class} = $html;
88          }          }
         $html = "<table>$html</table>" if $html;  
         $markup = $html;  
 }  
89    
90  sub request {          my $icons_html = $self->combine_images( @icons );
91          my ( $self, $req ) = @_;          sub icon {
92          my $html = $self->page( body => qq|<h1>Classes</h1>| . $self->markup );                  my ($icons_html,$path) = @_;
93          $req->print( $html );                  $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
94            };
95    
96            eval {
97    
98            $self->title('Frey');
99    
100            $self->add_css(qq|
101                    a.graph {
102                            color: #888;
103                            text-decoration: none;
104                    }
105            |);
106    
107            };
108            warn "FIXME: $@" if $@;
109    
110            return
111                    qq|<table>| . join("\n",
112                            map {
113                                    my $html = $row->{$_};
114                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
115                                    $html;
116                            }
117                            sort {
118                                    if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
119                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
120                                    } else {
121                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
122                                    }
123                            }
124                            keys %$row
125                    ) . qq|</table>|;
126  }  }
127    
128    __PACKAGE__->meta->make_immutable;
129    no Moose;
130    
131  1;  1;

Legend:
Removed from v.213  
changed lines
  Added in v.1133

  ViewVC Help
Powered by ViewVC 1.1.26