/[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 821 by dpavlin, Fri Dec 12 18:02:39 2008 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="/~/$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="/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 = @{ $runnable->{ $class } } if defined $runnable->{ $class };
67                  foreach my $try ( Frey::Run->execute ) {                  @runnable = $self->class_runnable( $class ) unless @runnable;
68                          push @inspect, qq|<a href="/$try/$package">$try</a>| if $package->can($try);  
69                  }                  my @run = map {
70                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;                          my $invoke = $_;
71                            s{^as_}{};
72                            s{_as_\w+}{};
73                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
74                    } @runnable;
75                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
76    
77                    my @inputs = $self->class_inputs( $class );
78    
79                    $usage->{$class} ||= 0;
80                    $html
81                            .= qq|</td><td>|
82                            . join(' ', @run)
83                            . qq|</td><td>|
84                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
85                            . qq|</td><td>|
86                            . ( $usage->{$class} || '' )
87                            . qq|</td></tr>|
88                            ;
89                    $row->{$class} = $html;
90          }          }
91          $html = "<table>$html</table>" if $html;  
92          $markup = $html;          my $icons_html = $self->combine_images( @icons );
93            sub icon {
94                    my ($icons_html,$path) = @_;
95                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
96            };
97    
98            $self->title('Frey');
99    
100            return
101                    qq|<table>| . join("\n",
102                            map {
103                                    my $html = $row->{$_};
104                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
105                                    $html;
106                            }
107                            sort {
108                                    if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
109                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
110                                    } else {
111                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
112                                    }
113                            }
114                            keys %$row
115                    ) . qq|</table>|;
116  }  }
117    
118  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26