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

Legend:
Removed from v.408  
changed lines
  Added in v.607

  ViewVC Help
Powered by ViewVC 1.1.26