/[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 144 by dpavlin, Wed Jul 16 16:03:09 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 1144 by dpavlin, Wed Jul 1 17:05:10 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    sub as_markup {
26            my $self = shift;
27            my $row;
28            my @icons;
29    
30            my $usage = $self->usage;
31            warn "# usage ",dump( $usage );
32    
33            my $runnable = $self->load('var/Frey/Class/Browser/runnable.yaml');
34    
35            foreach my $class ( $self->classes ) {
36    
37                    my $icon = $self->icon_path( $class );
38    
39                    if ($icon) {
40                            push @icons, $icon;
41                            $icon = qq|<!-- icon:$icon -->|;
42                    } else {
43                            $icon = '';
44                    }
45    
46                    my $html
47                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
48                            . $self->class_path( $class )
49                            . qq|">$class</a>
50                            <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>
51                            </td><td>|
52                            ;
53                    if ( $class->can('meta') ) {
54                            if ( $class->meta->isa('Moose::Meta::Role') ) {
55                                  $html .= qq|role|;                                  $html .= qq|role|;
56                          } else {                          } else {
57                                  $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');
58                          }                          }
59                  }                  }
60                  $html .= qq|</td><td>|;  
61                  $html .= qq|<a href="/ob/$package">collection</a>| if $package->can('collection_table');                  my @runnable = ();
62                  $html .= qq|</td></tr>|;                  @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class }; # FIXME needs review
63                    @runnable = $self->class_runnable( $class ) unless @runnable;
64    
65                    my @run = map {
66                            my $invoke = $_;
67                            s{^as_}{};
68                            s{_as_\w+}{};
69                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
70                    } @runnable;
71                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
72    
73                    my @inputs = $self->class_inputs( $class );
74    
75                    $usage->{$class} ||= 0;
76                    $html
77                            .= qq|</td><td>|
78                            . join(' ', @run)
79                            . qq|</td><td>|
80                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
81                            . qq|</td><td>|
82                            . ( $usage->{$class} || '' )
83                            . qq|</td></tr>|
84                            ;
85                    $row->{$class} = $html;
86          }          }
         $html = "<table>$html</table>" if $html;  
         $markup = $html;  
 }  
87    
88  sub html {          my $icons_html = $self->combine_images( @icons );
89          my ( $self, $req ) = @_;          sub icon {
90          my $html = $self->page( body => qq|<h1>Classes</h1>| . $self->markup );                  my ($icons_html,$path) = @_;
91          $req->print( $html );                  $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
92            };
93    
94            eval {
95    
96            $self->title('Frey');
97    
98            $self->add_css(qq|
99                    a.graph {
100                            color: #888;
101                            text-decoration: none;
102                    }
103            |);
104    
105            };
106            warn "FIXME: $@" if $@;
107    
108            return
109                    qq|<table>| . join("\n",
110                            map {
111                                    my $html = $row->{$_};
112                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
113                                    $html;
114                            }
115                            sort {
116                                    if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
117                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
118                                    } else {
119                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
120                                    }
121                            }
122                            keys %$row
123                    ) . qq|</table>|;
124  }  }
125    
126    __PACKAGE__->meta->make_immutable;
127    no Moose;
128    
129  1;  1;

Legend:
Removed from v.144  
changed lines
  Added in v.1144

  ViewVC Help
Powered by ViewVC 1.1.26