/[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 119 by dpavlin, Sun Jul 13 18:51:29 2008 UTC trunk/lib/Frey/Class/Browser.pm revision 795 by dpavlin, Wed Dec 10 17:57:10 2008 UTC
# Line 1  Line 1 
1  package Frey::ClassBrowser;  package Frey::Class::Browser;
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_sort' => (
13            is => 'rw',
14            isa => 'Bool',
15            default => 0,
16            documentation => 'Sort by class usage',
17    );
18    
19  sub html_markup {  has 'usage_on_top' => (
20            is => 'rw',
21            isa => 'Bool',
22            default => 1,
23            documentation => 'Show usage on top of list',
24    );
25    
26    our $usage;
27    
28    sub as_markup {
29          my $self = shift;          my $self = shift;
30          return $markup if $markup;          my $row;
31          my $f = Frey::ClassLoader->new;          my @icons;
32          my $classes = dom2html(  
33                  table => [          $usage ||= $self->session_dump( $self->usage );
34            #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            foreach my $class ( $self->classes ) {
42    
43                    my $icon = $self->icon_path( $class );
44                    if ($icon) {
45                            push @icons, $icon;
46                            $icon = qq|<!-- icon:$icon -->|;
47                    } else {
48                            $icon = '';
49                    }
50    
51                    my $html
52                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
53                            . $self->class_path( $class )
54                            . qq|">$class</a></td><td>|
55                            ;
56                    if ( $class->can('meta') ) {
57                            if ( $class->meta->isa('Moose::Meta::Role') ) {
58                                    $html .= qq|role|;
59                            } else {
60                                    $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
61                            }
62                    }
63    
64                    my @run = map {
65                            my $invoke = $_;
66                            s{^as_}{};
67                            s{_as_\w+}{};
68                            qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
69                    } $self->class_runnable( $class );
70                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
71    
72                    my @inputs = $self->class_inputs( $class );
73    
74                    $usage->{$class} ||= 0;
75                    $html
76                            .= qq|</td><td>|
77                            . join(' ', @run)
78                            . qq|</td><td>|
79                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
80                            . qq|</td><td>|
81                            . ( $usage->{$class} || '' )
82                            . qq|</td></tr>|
83                            ;
84                    $row->{$class} = $html;
85            }
86    
87            my $icons_html = $self->combine_images( @icons );
88            sub icon {
89                    my ($icons_html,$path) = @_;
90                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
91            };
92    
93            $self->title('Frey');
94    
95            return
96                    qq|<table>| . join("\n",
97                          map {                          map {
98                                  my $package = $_;                                  my $html = $row->{$_};
99                                  ( tr => [                                  $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
100                                          td => [ a => { href => '/~/' . $package, title => $f->package_path( $package ) } => [ $package ] ],                                  $html;
101                                          td => [                          }
102                                                  $package->can('meta') ?                          sort {
103                                                          $package->meta->isa('Moose::Meta::Role') ? 'role' :                                  if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
104                                                          ( a => { href => '/od/' . $package } => [ 'design' ] ) :                                          $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
105                                                  ''                                  } else {
106                                          ],                                          $self->usage_on_top ? $a cmp $b : $b cmp $a;
107                                          td => [ $package->can('collection_table') ? ( a => { href => '/ob/' . $package } => [ 'collection' ] ) : '' ],                                  }
108                                  ] )                          }
109                          } $f->classes                          keys %$row
110                  ],                  ) . qq|</table>|;
         );  
         $markup = $classes;  
111  }  }
112    
113  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26