/[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 555 by dpavlin, Thu Nov 27 17:39:00 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                            warn "FIXME: 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                    }
38    
39                    my $html
40                            = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
41                            . $self->class_path( $class )
42                            . qq|">$class</a></td><td>|
43                            ;
44                    if ( $class->can('meta') ) {
45                            if ( $class->meta->isa('Moose::Meta::Role') ) {
46                                    $html .= qq|role|;
47                            } else {
48                                    $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
49                            }
50                    }
51    
52                    my @run = map {
53                            s{^as_}{};
54                            qq|<a target="$class" href="/$class/as_$_" title="$class->as_$_">$_</a>|;
55                    } $self->class_runnable( $class );
56                    push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
57    
58                    my @inputs = $self->class_inputs( $class );
59    
60                    $usage->{$class} ||= 0;
61                    $html
62                            .= qq|</td><td>|
63                            . join(' ', @run)
64                            . qq|</td><td>|
65                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
66                            . qq|</td><td>|
67                            . ( $usage->{$class} || '' )
68                            . qq|</td></tr>|
69                            ;
70                    $row->{$class} = $html;
71            }
72    
73            my $icons_html = $self->combine_images( @icons );
74            sub icon {
75                    my $path = shift;
76                    warn "# icon $path";
77                    $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
78            };
79    
80  sub markup {          return
81          my $f = Frey::ClassLoader->new;                  qq|<table>| . join("\n",
         my $classes = dom2html(  
                 table => [  
82                          map {                          map {
83                                  my $package = $_;                                  my $html = $row->{$_};
84                                  ( tr => [                                  $html =~ s{<!-- icon:(\S+) -->}{icon($1)}gse;
85                                          td => [ a => { href => '/~/' . $package, title => $f->package_path( $package ) } => [ $package ] ],                                  $html;
86                                          td => [                          }
87                                                  $package->can('meta') ?                          sort {
88                                                          $package->meta->isa('Moose::Meta::Role') ? 'role' :                                  if ( $usage->{$a} || $usage->{$b} ) {
89                                                          ( a => { href => '/od/' . $package } => [ 'design' ] ) :                                          $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
90                                                  ''                                  } else {
91                                          ],                                          $self->usage_on_top ? $a cmp $b : $b cmp $a;
92                                          td => [ $package->can('collection_table') ? ( a => { href => '/ob/' . $package } => [ 'collection' ] ) : '' ],                                  }
93                                  ] )                          }
94                          } $f->classes                          keys %$row
95                  ],                  ) . qq|</table>|;
         );  
         $markup = $classes;  
 }  
   
 sub html {  
         my ( $self, $req ) = @_;  
         my $html = $self->page( body => qq|<h1>Classes</h1>| . $self->markup );  
         $req->print( $html );  
96  }  }
97    
98  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26