/[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 279 by dpavlin, Wed Nov 5 08:20:52 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 925 by dpavlin, Mon Jan 5 22:08:48 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    
 use Frey::ClassLoader;  
9  use Frey::Run;  use Frey::Run;
10    use Data::Dump qw/dump/;
11    
12  our $markup;  has 'usage_sort' => (
13            is => 'rw',
14            isa => 'Bool',
15            default => 0,
16            documentation => 'Sort by class usage',
17    );
18    
19  sub markup {  has 'usage_on_top' => (
20          return $markup if $markup;          is => 'rw',
21          my $f = Frey::ClassLoader->new;          isa => 'Bool',
22          my $html;          default => 1,
23          foreach my $package ( $f->classes ) {          documentation => 'Show usage on top of list',
24                  $html .= qq|<tr><td><a href="/Frey-Introspect/markup?class=$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;  );
25                  if ( $package->can('meta') ) {  
26                          if ( $package->meta->isa('Moose::Meta::Role') ) {  our $usage;
27    
28    sub as_markup {
29            my $self = shift;
30            my $row;
31            my @icons;
32    
33            $usage ||= $self->session_dump( $self->usage );
34            #warn "# usage ",dump( $usage );
35    
36            if ( ! $self->can('icon_path') ) {
37                    $self->TODO( "re-apply Frey::Web on $self" );
38                    Frey::Web->meta->apply( $self );
39            }
40    
41            my $runnable = $self->load('var/Frey/Class/Browser/runnable.yaml');
42    
43            foreach my $class ( $self->classes ) {
44    
45                    my $icon = $self->icon_path( $class );
46                    if ($icon) {
47                            push @icons, $icon;
48                            $icon = qq|<!-- icon:$icon -->|;
49                    } else {
50                            $icon = '';
51                    }
52    
53                    my $html
54                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
55                            . $self->class_path( $class )
56                            . qq|">$class</a></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="/Frey-ObjectDesigner?class=$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="/Frey-ObjectBrowser?class=$package">collection</a>| if $package->can('collection_table');                  my @runnable = ();
67                  foreach my $try ( Frey::Run->execute ) {                  @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class }; # FIXME needs review
68                          push @inspect, qq|<a href="/$package/$try">$try</a>| if $package->can($try);                  @runnable = $self->class_runnable( $class ) unless @runnable;
69                  }  
70                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;                  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');
100    
101            return
102                    qq|<table>| . join("\n",
103                            map {
104                                    my $html = $row->{$_};
105                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
106                                    $html;
107                            }
108                            sort {
109                                    if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
110                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
111                                    } else {
112                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
113                                    }
114                            }
115                            keys %$row
116                    ) . qq|</table>|;
117  }  }
118    
119  1;  1;

Legend:
Removed from v.279  
changed lines
  Added in v.925

  ViewVC Help
Powered by ViewVC 1.1.26