/[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 217 by dpavlin, Fri Oct 31 22:41:34 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 1109 by dpavlin, Mon Jun 29 16:54:02 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';
5    
6    extends 'Frey::Class::Loader';
7  with 'Frey::Web';  with 'Frey::Web';
8    with 'Frey::Session';
9    with 'Frey::Web::CombineImages';
10    with 'Frey::Class::Icon';
11    
12    use Data::Dump qw/dump/;
13    
14    has 'usage_sort' => (
15            is => 'rw',
16            isa => 'Bool',
17            default => 0,
18            documentation => 'Sort by class usage',
19    );
20    
21    has 'usage_on_top' => (
22            is => 'rw',
23            isa => 'Bool',
24            default => 1,
25            documentation => 'Show usage on top of list',
26    );
27    
28    our $usage;
29    
30    sub as_markup {
31            my $self = shift;
32            my $row;
33            my @icons;
34    
35  use Frey::ClassLoader;          $usage ||= $self->session_dump( $self->usage );
36            #warn "# usage ",dump( $usage );
37    
38  our $markup;          my $runnable = $self->load('var/Frey/Class/Browser/runnable.yaml');
39    
40  sub markup {          foreach my $class ( $self->classes ) {
41          return $markup if $markup;  
42          my $f = Frey::ClassLoader->new;                  my $icon = $self->icon_path( $class );
43          my $html;  
44          foreach my $package ( $f->classes ) {                  if ($icon) {
45                  $html .= qq|<tr><td><a href="/~/$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;                          push @icons, $icon;
46                  if ( $package->can('meta') ) {                          $icon = qq|<!-- icon:$icon -->|;
47                          if ( $package->meta->isa('Moose::Meta::Role') ) {                  } else {
48                            $icon = '';
49                    }
50    
51                    my $html
52                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
53                            . $self->class_path( $class )
54                            . qq|">$class</a>
55                            <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>
56                            </td><td>|
57                            ;
58                    if ( $class->can('meta') ) {
59                            if ( $class->meta->isa('Moose::Meta::Role') ) {
60                                  $html .= qq|role|;                                  $html .= qq|role|;
61                          } else {                          } else {
62                                  $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');
63                          }                          }
64                  }                  }
65                  my @inspect;  
66                  push @inspect, qq|<a href="/ob/$package">collection</a>| if $package->can('collection_table');                  my @runnable = ();
67                  push @inspect, qq|<a href="/markup/$package">markup</a>| if $package->can('markup');                  @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class }; # FIXME needs review
68                  push @inspect, qq|<a href="/request/$package">request</a>| if $package->can('request');                  @runnable = $self->class_runnable( $class ) unless @runnable;
69                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;  
70                    my @run = map {
71                            my $invoke = $_;
72                            s{^as_}{};
73                            s{_as_\w+}{};
74                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
75                    } @runnable;
76                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
77    
78                    my @inputs = $self->class_inputs( $class );
79    
80                    $usage->{$class} ||= 0;
81                    $html
82                            .= qq|</td><td>|
83                            . join(' ', @run)
84                            . qq|</td><td>|
85                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
86                            . qq|</td><td>|
87                            . ( $usage->{$class} || '' )
88                            . qq|</td></tr>|
89                            ;
90                    $row->{$class} = $html;
91          }          }
92          $html = "<table>$html</table>" if $html;  
93          $markup = $html;          my $icons_html = $self->combine_images( @icons );
94            sub icon {
95                    my ($icons_html,$path) = @_;
96                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
97            };
98    
99            $self->title('Frey') if $self->can('title'); # FIXME
100    
101            $self->add_css(qq|
102                    a.graph {
103                            color: #888;
104                            text-decoration: none;
105                    }
106            |);
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  1;  1;

Legend:
Removed from v.217  
changed lines
  Added in v.1109

  ViewVC Help
Powered by ViewVC 1.1.26