/[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 555 by dpavlin, Thu Nov 27 17:39:00 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::ClassLoader';  extends 'Frey::Class::Loader';
5  with 'Frey::Web';  with 'Frey::Web';
6  with 'Frey::Session';  with 'Frey::Session';
7  with 'Frey::Web::CombineImages';  with 'Frey::Web::CombineImages';
# Line 9  with 'Frey::Web::CombineImages'; Line 9  with 'Frey::Web::CombineImages';
9  use Frey::Run;  use Frey::Run;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11    
12    has 'usage_sort' => (
13            is => 'rw',
14            isa => 'Bool',
15            default => 0,
16            documentation => 'Sort by class usage',
17    );
18    
19  has 'usage_on_top' => (  has 'usage_on_top' => (
20          is => 'rw',          is => 'rw',
21          isa => 'Bool',          isa => 'Bool',
# Line 16  has 'usage_on_top' => ( Line 23  has 'usage_on_top' => (
23          documentation => 'Show usage on top of list',          documentation => 'Show usage on top of list',
24  );  );
25    
26    our $usage;
27    
28  sub as_markup {  sub as_markup {
29          my $self = shift;          my $self = shift;
30          my $row;          my $row;
31          my @icons;          my @icons;
32    
33          my $usage = $self->session_dump( $self->usage );          $usage ||= $self->session_dump( $self->usage );
34          #warn "# usage ",dump( $usage );          #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 ) {          foreach my $class ( $self->classes ) {
44    
45                  my $icon = '';                  my $icon = $self->icon_path( $class );
                 if ( ! $self->can('icon_path') ) {  
                         warn "FIXME: re-apply Frey::Web on $self";  
                         Frey::Web->meta->apply( $self );  
                 }  
                 $icon = $self->icon_path( $class );  
46                  if ($icon) {                  if ($icon) {
47                          push @icons, $icon;                          push @icons, $icon;
48                          $icon = qq|<!-- icon:$icon -->|;                          $icon = qq|<!-- icon:$icon -->|;
49                    } else {
50                            $icon = '';
51                  }                  }
52    
53                  my $html                  my $html
# Line 49  sub as_markup { Line 63  sub as_markup {
63                          }                          }
64                  }                  }
65    
66                    my @runnable = @{ $runnable->{ $class } } if defined $runnable->{ $class };
67                    @runnable = $self->class_runnable( $class ) unless @runnable;
68    
69                  my @run = map {                  my @run = map {
70                            my $invoke = $_;
71                          s{^as_}{};                          s{^as_}{};
72                          qq|<a target="$class" href="/$class/as_$_" title="$class->as_$_">$_</a>|;                          s{_as_\w+}{};
73                  } $self->class_runnable( $class );                          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');                  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 );                  my @inputs = $self->class_inputs( $class );
# Line 72  sub as_markup { Line 91  sub as_markup {
91    
92          my $icons_html = $self->combine_images( @icons );          my $icons_html = $self->combine_images( @icons );
93          sub icon {          sub icon {
94                  my $path = shift;                  my ($icons_html,$path) = @_;
                 warn "# icon $path";  
95                  $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);                  $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
96          };          };
97    
98            $self->title('Frey');
99    
100          return          return
101                  qq|<table>| . join("\n",                  qq|<table>| . join("\n",
102                          map {                          map {
103                                  my $html = $row->{$_};                                  my $html = $row->{$_};
104                                  $html =~ s{<!-- icon:(\S+) -->}{icon($1)}gse;                                  $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
105                                  $html;                                  $html;
106                          }                          }
107                          sort {                          sort {
108                                  if ( $usage->{$a} || $usage->{$b} ) {                                  if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
109                                          $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};                                          $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
110                                  } else {                                  } else {
111                                          $self->usage_on_top ? $a cmp $b : $b cmp $a;                                          $self->usage_on_top ? $a cmp $b : $b cmp $a;

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

  ViewVC Help
Powered by ViewVC 1.1.26