/[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 223 by dpavlin, Sat Nov 1 00:14:05 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 1100 by dpavlin, Sun Jun 28 22:22:20 2009 UTC
# Line 1  Line 1 
1  package Frey::ClassBrowser;  package Frey::Class::Browser;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  extends 'Frey::Class::Loader';
5    with 'Frey::Web';
6    with 'Frey::Session';
7    with 'Frey::Web::CombineImages';
8    
9    use lib 'lib';
10    
 use Frey::ClassLoader;  
11  use Frey::Run;  use Frey::Run;
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            $usage ||= $self->session_dump( $self->usage );
36            #warn "# usage ",dump( $usage );
37    
38  our $markup;          if ( ! $self->can('icon_path') ) {
39                    $self->TODO( "re-apply Frey::Web on $self" );
40                    Frey::Web->meta->apply( $self );
41            }
42    
43            my $runnable = $self->load('var/Frey/Class/Browser/runnable.yaml');
44    
45            foreach my $class ( $self->classes ) {
46    
47  sub markup {                  my $icon = $self->icon_path( $class );
48          return $markup if $markup;                  if ($icon) {
49          my $f = Frey::ClassLoader->new;                          push @icons, $icon;
50          my $html;                          $icon = qq|<!-- icon:$icon -->|;
51          foreach my $package ( $f->classes ) {                  } else {
52                  $html .= qq|<tr><td><a href="/~/$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;                          $icon = '';
53                  if ( $package->can('meta') ) {                  }
54                          if ( $package->meta->isa('Moose::Meta::Role') ) {  
55                    my $html
56                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
57                            . $self->class_path( $class )
58                            . qq|">$class</a>
59                            <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>
60                            </td><td>|
61                            ;
62                    if ( $class->can('meta') ) {
63                            if ( $class->meta->isa('Moose::Meta::Role') ) {
64                                  $html .= qq|role|;                                  $html .= qq|role|;
65                          } else {                          } else {
66                                  $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');
67                          }                          }
68                  }                  }
69                  my @inspect;  
70                  push @inspect, qq|<a href="/ob/$package">collection</a>| if $package->can('collection_table');                  my @runnable = ();
71                  foreach my $try ( Frey::Run->execute ) {                  @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class }; # FIXME needs review
72                          push @inspect, qq|<a href="/$try/$package">$try</a>| if $package->can($try);                  @runnable = $self->class_runnable( $class ) unless @runnable;
73                  }  
74                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;                  my @run = map {
75                            my $invoke = $_;
76                            s{^as_}{};
77                            s{_as_\w+}{};
78                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
79                    } @runnable;
80                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
81    
82                    my @inputs = $self->class_inputs( $class );
83    
84                    $usage->{$class} ||= 0;
85                    $html
86                            .= qq|</td><td>|
87                            . join(' ', @run)
88                            . qq|</td><td>|
89                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
90                            . qq|</td><td>|
91                            . ( $usage->{$class} || '' )
92                            . qq|</td></tr>|
93                            ;
94                    $row->{$class} = $html;
95          }          }
96          $html = "<table>$html</table>" if $html;  
97          $markup = $html;          my $icons_html = $self->combine_images( @icons );
98            sub icon {
99                    my ($icons_html,$path) = @_;
100                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
101            };
102    
103            $self->title('Frey');
104    
105            $self->add_css(qq|
106                    a.graph {
107                            color: #888;
108                            text-decoration: none;
109                    }
110            |);
111    
112            return
113                    qq|<table>| . join("\n",
114                            map {
115                                    my $html = $row->{$_};
116                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
117                                    $html;
118                            }
119                            sort {
120                                    if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
121                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
122                                    } else {
123                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
124                                    }
125                            }
126                            keys %$row
127                    ) . qq|</table>|;
128  }  }
129    
130  1;  1;

Legend:
Removed from v.223  
changed lines
  Added in v.1100

  ViewVC Help
Powered by ViewVC 1.1.26