/[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

Contents of /trunk/lib/Frey/ClassBrowser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 570 - (show annotations)
Thu Nov 27 22:11:13 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2348 byte(s)
tweaks all over the place
1 package Frey::ClassBrowser;
2 use Moose;
3
4 extends 'Frey::ClassLoader';
5 with 'Frey::Web';
6 with 'Frey::Session';
7 with 'Frey::Web::CombineImages';
8
9 use Frey::Run;
10 use Data::Dump qw/dump/;
11
12 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 s{^as_}{};
56 qq|<a target="$class" href="/$class/as_$_" title="$class->as_$_">$_</a>|;
57 } $self->class_runnable( $class );
58 push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
59
60 my @inputs = $self->class_inputs( $class );
61
62 $usage->{$class} ||= 0;
63 $html
64 .= qq|</td><td>|
65 . join(' ', @run)
66 . qq|</td><td>|
67 . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
68 . qq|</td><td>|
69 . ( $usage->{$class} || '' )
70 . qq|</td></tr>|
71 ;
72 $row->{$class} = $html;
73 }
74
75 my $icons_html = $self->combine_images( @icons );
76 sub icon {
77 my ($icons_html,$path) = @_;
78 warn "# icon $path";
79 $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
80 };
81
82 return
83 qq|<table>| . join("\n",
84 map {
85 my $html = $row->{$_};
86 $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
87 $html;
88 }
89 sort {
90 if ( $usage->{$a} || $usage->{$b} ) {
91 $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
92 } else {
93 $self->usage_on_top ? $a cmp $b : $b cmp $a;
94 }
95 }
96 keys %$row
97 ) . qq|</table>|;
98 }
99
100 1;

  ViewVC Help
Powered by ViewVC 1.1.26