/[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 121 by dpavlin, Mon Jul 14 21:22:43 2008 UTC revision 582 by dpavlin, Fri Nov 28 13:18:18 2008 UTC
# Line 1  Line 1 
1  package Frey::ClassBrowser;  package Frey::ClassBrowser;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  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 as_markup {
20            my $self = shift;
21            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 ) {
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
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') ) {
47                            if ( $class->meta->isa('Moose::Meta::Role') ) {
48                                    $html .= qq|role|;
49                            } else {
50                                    $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
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
66                            .= qq|</td><td>|
67                            . join(' ', @run)
68                            . qq|</td><td>|
69                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
70                            . qq|</td><td>|
71                            . ( $usage->{$class} || '' )
72                            . qq|</td></tr>|
73                            ;
74                    $row->{$class} = $html;
75            }
76    
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  sub markup {          return
84          my $f = Frey::ClassLoader->new;                  qq|<table>| . join("\n",
         my $classes = dom2html(  
                 table => [  
85                          map {                          map {
86                                  my $package = $_;                                  my $html = $row->{$_};
87                                  ( tr => [                                  $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
88                                          td => [ a => { href => '/~/' . $package, title => $f->package_path( $package ) } => [ $package ] ],                                  $html;
89                                          td => [                          }
90                                                  $package->can('meta') ?                          sort {
91                                                          $package->meta->isa('Moose::Meta::Role') ? 'role' :                                  if ( $usage->{$a} || $usage->{$b} ) {
92                                                          ( a => { href => '/od/' . $package } => [ 'design' ] ) :                                          $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                                          td => [ $package->can('collection_table') ? ( a => { href => '/ob/' . $package } => [ 'collection' ] ) : '' ],                                  }
96                                  ] )                          }
97                          } $f->classes                          keys %$row
98                  ],                  ) . qq|</table>|;
         );  
         $markup = $classes;  
 }  
   
 sub html {  
         my ( $self, $req ) = @_;  
         my $html = $self->page( body => qq|<h1>Classes</h1>| . $self->markup );  
         $req->print( $html );  
99  }  }
100    
101  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26