/[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 418 by dpavlin, Tue Nov 18 16:54:10 2008 UTC revision 570 by dpavlin, Thu Nov 27 22:11:13 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  our $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 markup {  sub as_markup {
20          my $self = shift;          my $self = shift;
21          return $markup if $markup;          my $row;
22          my $html;          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                  $html .= qq|<tr><td><a href="/$class" title="| . $self->class_path( $class ) . qq|">$class</a></td><td>|;  
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
42                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
43                            . $self->class_path( $class )
44                            . qq|">$class</a></td><td>|
45                            ;
46                  if ( $class->can('meta') ) {                  if ( $class->can('meta') ) {
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                  $html .= qq|</td><td>| . join(' ', @run) . qq|</td><td>| .  
54                          ( @input ? '&larr; ' . join(' ', @input) : '' ) .                  my @run = map {
55                          qq|</td></tr>|;                          s{^as_}{};
56                            qq|<a target="$class" href="/$class/as_$_" title="$class->as_$_">$_</a>|;
57                    } $self->class_runnable( $class );
58                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
59    
60                    my @inputs = $self->class_inputs( $class );
61    
62                    $usage->{$class} ||= 0;
63                    $html
64                            .= qq|</td><td>|
65                            . join(' ', @run)
66                            . qq|</td><td>|
67                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
68                            . qq|</td><td>|
69                            . ( $usage->{$class} || '' )
70                            . qq|</td></tr>|
71                            ;
72                    $row->{$class} = $html;
73          }          }
74          $html = "<table>$html</table>" if $html;  
75          $markup = $html;          my $icons_html = $self->combine_images( @icons );
76            sub icon {
77                    my ($icons_html,$path) = @_;
78                    warn "# icon $path";
79                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
80            };
81    
82            return
83                    qq|<table>| . join("\n",
84                            map {
85                                    my $html = $row->{$_};
86                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
87                                    $html;
88                            }
89                            sort {
90                                    if ( $usage->{$a} || $usage->{$b} ) {
91                                            $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
92                                    } else {
93                                            $self->usage_on_top ? $a cmp $b : $b cmp $a;
94                                    }
95                            }
96                            keys %$row
97                    ) . qq|</table>|;
98  }  }
99    
100  1;  1;

Legend:
Removed from v.418  
changed lines
  Added in v.570

  ViewVC Help
Powered by ViewVC 1.1.26