/[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 187 by dpavlin, Sat Sep 13 15:31:54 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  sub markup {                  my $html
42          return $markup if $markup;                          = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
43          my $f = Frey::ClassLoader->new;                          . $self->class_path( $class )
44          my $html;                          . qq|">$class</a></td><td>|
45          foreach my $package ( $f->classes ) {                          ;
46                  $html .= qq|<tr><td><a href="/~/$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;                  if ( $class->can('meta') ) {
47                  if ( $package->can('meta') ) {                          if ( $class->meta->isa('Moose::Meta::Role') ) {
                         if ( $package->meta->isa('Moose::Meta::Role') ) {  
48                                  $html .= qq|role|;                                  $html .= qq|role|;
49                          } else {                          } else {
50                                  $html .= qq|<a href="/od/$package">design</a>| if $package->can('collection');                                  $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
51                          }                          }
52                  }                  }
53                  my @inspect;  
54                  push @inspect, qq|<a href="/ob/$package">collection</a>| if $package->can('collection_table');                  my @run = map {
55                  push @inspect, qq|<a href="/markup/$package">markup</a>| if $package->can('markup');                          my $invoke = $_;
56                  push @inspect, qq|<a href="/html/$package">html</a>| if $package->can('html');                          s{^as_}{};
57                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;                          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          }          }
         $html = "<table>$html</table>" if $html;  
         $markup = $html;  
 }  
76    
77  sub html {          my $icons_html = $self->combine_images( @icons );
78          my ( $self, $req ) = @_;          sub icon {
79          my $html = $self->page( body => qq|<h1>Classes</h1>| . $self->markup );                  my ($icons_html,$path) = @_;
80          $req->print( $html );                  $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
81            };
82    
83            return
84                    qq|<table>| . join("\n",
85                            map {
86                                    my $html = $row->{$_};
87                                    $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
88                                    $html;
89                            }
90                            sort {
91                                    if ( $usage->{$a} || $usage->{$b} ) {
92                                            $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                                    }
96                            }
97                            keys %$row
98                    ) . qq|</table>|;
99  }  }
100    
101  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26