/[Frey]/trunk/lib/Frey/ClassBrowser.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/ClassBrowser.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 292 by dpavlin, Wed Nov 5 08:21:03 2008 UTC revision 530 by dpavlin, Wed Nov 26 04:27: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';
6    with 'Frey::Session';
7    
 use Frey::ClassLoader;  
8  use Frey::Run;  use Frey::Run;
9    use Data::Dump qw/dump/;
10    
11  our $markup;  has 'usage_on_top' => (
12            is => 'rw',
13            isa => 'Bool',
14            default => 1,
15            documentation => 'Show usage on top of list',
16    );
17    
18  sub markup {  sub as_markup {
19          return $markup if $markup;          my $self = shift;
20          my $f = Frey::ClassLoader->new;          my $row;
21          my $html;  
22          foreach my $package ( $f->classes ) {          my $usage = $self->session_dump( $self->usage );
23                  $html .= qq|<tr><td><a href="/$package" title="| . $f->package_path( $package ) . qq|">$package</a></td><td>|;          #warn "# usage ",dump( $usage );
24                  if ( $package->can('meta') ) {          foreach my $class ( $self->classes ) {
25                          if ( $package->meta->isa('Moose::Meta::Role') ) {                  my $icon_path;
26                    eval { $icon_path = $self->icon_path( $class ); };
27                    my $html
28                            = qq|<tr><td>|
29                            . ( $icon_path ? qq|<img src="/$icon_path" alt="$class">| : '?' )
30                            . qq|</td><td><a target="introspect" href="/$class" title="|
31                            . $self->class_path( $class )
32                            . qq|">$class</a></td><td>|
33                            ;
34                    if ( $class->can('meta') ) {
35                            if ( $class->meta->isa('Moose::Meta::Role') ) {
36                                  $html .= qq|role|;                                  $html .= qq|role|;
37                          } else {                          } else {
38                                  $html .= qq|<a href="/Frey-ObjectDesigner?class=$package">design</a>| if $package->can('collection');                                  $html .= qq|<a href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
39                          }                          }
40                  }                  }
41                  my @inspect;  
42                  push @inspect, qq|<a href="/Frey-ObjectBrowser?class=$package">collection</a>| if $package->can('collection_table');                  my @run = map {
43                  foreach my $try ( Frey::Run->execute ) {                          s{^as_}{};
44                          push @inspect, qq|<a href="/$package/$try">$try</a>| if $package->can($try);                          qq|<a href="/$class/as_$_" title="$class->as_$_">$_</a>|;
45                  }                  } $self->class_runnable( $class );
46                  $html .= qq|</td><td>| . join('&nbsp;', @inspect) . qq|</td></tr>|;                  push @run, qq|<a href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
47    
48                    my @inputs = $self->class_inputs( $class );
49    
50                    $usage->{$class} ||= 0;
51                    $html
52                            .= qq|</td><td>|
53                            . join(' ', @run)
54                            . qq|</td><td>|
55                            . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
56                            . qq|</td><td>|
57                            . ( $usage->{$class} || '' )
58                            . qq|</td></tr>|
59                            ;
60                    $row->{$class} = $html;
61          }          }
62          $html = "<table>$html</table>" if $html;  
63          $markup = $html;          return
64                    qq|<table>| . join("\n",
65                            map { $row->{$_} }
66                            sort {
67                                    if ( $usage->{$a} || $usage->{$b} ) {
68                                            if ( $self->usage_on_top ) {
69                                                    $usage->{$b} <=> $usage->{$a};
70                                            } else {
71                                                    $usage->{$a} <=> $usage->{$b};
72                                            }
73                                    } else {
74                                            $a cmp $b;
75                                    }
76                            }
77                            keys %$row
78                    ) . qq|</table>|;
79  }  }
80    
81  1;  1;

Legend:
Removed from v.292  
changed lines
  Added in v.530

  ViewVC Help
Powered by ViewVC 1.1.26