/[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

revision 427 by dpavlin, Tue Nov 18 23:42:40 2008 UTC revision 582 by dpavlin, Fri Nov 28 13:18:18 2008 UTC
# Line 3  use Moose; Line 3  use Moose;
3    
4  extends 'Frey::ClassLoader';  extends 'Frey::ClassLoader';
5  with 'Frey::Web';  with 'Frey::Web';
6    with 'Frey::Session';
7    with 'Frey::Web::CombineImages';
8    
9  use Frey::Run;  use Frey::Run;
10    use Data::Dump qw/dump/;
11    
12  sub markup {  has 'usage_on_top' => (
13            is => 'rw',
14            isa => 'Bool',
15            default => 1,
16            documentation => 'Show usage on top of list',
17    );
18    
19    sub as_markup {
20          my $self = shift;          my $self = shift;
21          my @rows;          my $row;
22            my @icons;
23    
24            my $usage = $self->session_dump( $self->usage );
25            #warn "# usage ",dump( $usage );
26          foreach my $class ( $self->classes ) {          foreach my $class ( $self->classes ) {
27    
28                    my $icon = '';
29                    if ( ! $self->can('icon_path') ) {
30                            $self->TODO( "re-apply Frey::Web on $self" );
31                            Frey::Web->meta->apply( $self );
32                    }
33                    $icon = $self->icon_path( $class );
34                    if ($icon) {
35                            push @icons, $icon;
36                            $icon = qq|<!-- icon:$icon -->|;
37                    } else {
38                            $icon = '';
39                    }
40    
41                  my $html                  my $html
42                          = qq|<tr><td><a href="/$class" title="|                          = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
43                          . $self->class_path( $class )                          . $self->class_path( $class )
44                          . qq|">$class</a></td><td>|                          . qq|">$class</a></td><td>|
45                          ;                          ;
# Line 19  sub markup { Line 47  sub markup {
47                          if ( $class->meta->isa('Moose::Meta::Role') ) {                          if ( $class->meta->isa('Moose::Meta::Role') ) {
48                                  $html .= qq|role|;                                  $html .= qq|role|;
49                          } else {                          } else {
50                                  $html .= qq|<a href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');                                  $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
                         }  
                 }  
                 my @run;  
                 my @input;  
                 push @run, qq|<a href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');  
                 my $class_method = $self->class_methods( $class );  
                 foreach my $try ( Frey::Run->runnable ) {  
                         next unless $class->can($try);  
                         if ( $class_method->{ $try } ) {  
                                 push @run, qq|<a href="/$class/$try">$try</a>|;  
                         } else {  
                                 push @input, $try;  
51                          }                          }
52                  }                  }
53    
54                    my @run = map {
55                            my $invoke = $_;
56                            s{^as_}{};
57                            s{_as_\w+}{};
58                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
59                    } $self->class_runnable( $class );
60                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
61    
62                    my @inputs = $self->class_inputs( $class );
63    
64                    $usage->{$class} ||= 0;
65                  $html                  $html
66                          .= qq|</td><td>|                          .= qq|</td><td>|
67                          . join(' ', @run)                          . join(' ', @run)
68                          . qq|</td><td>|                          . qq|</td><td>|
69                          . ( @input ? '&larr; ' . join(' ', @input) : '' )                          . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
70                            . qq|</td><td>|
71                            . ( $usage->{$class} || '' )
72                          . qq|</td></tr>|                          . qq|</td></tr>|
73                          ;                          ;
74                  push @rows, $html if $html;                  $row->{$class} = $html;
75          }          }
76          return qq|<table>| . join("\n", @rows) . qq|</table>| if @rows;  
77            my $icons_html = $self->combine_images( @icons );
78            sub icon {
79                    my ($icons_html,$path) = @_;
80                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
81            };
82    
83            return
84                    qq|<table>| . join("\n",
85                            map {
86                                    my $html = $row->{$_};
87                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
88                                    $html;
89                            }
90                            sort {
91                                    if ( $usage->{$a} || $usage->{$b} ) {
92                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
93                                    } else {
94                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
95                                    }
96                            }
97                            keys %$row
98                    ) . qq|</table>|;
99  }  }
100    
101  1;  1;

Legend:
Removed from v.427  
changed lines
  Added in v.582

  ViewVC Help
Powered by ViewVC 1.1.26