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

Legend:
Removed from v.119  
changed lines
  Added in v.653

  ViewVC Help
Powered by ViewVC 1.1.26