/[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 555 - (show annotations)
Thu Nov 27 17:39:00 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 2296 byte(s)
extracted Frey::Web::CombineImages and use it also from ClassBrowser
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 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 return
81 qq|<table>| . join("\n",
82 map {
83 my $html = $row->{$_};
84 $html =~ s{<!-- icon:(\S+) -->}{icon($1)}gse;
85 $html;
86 }
87 sort {
88 if ( $usage->{$a} || $usage->{$b} ) {
89 $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 }
93 }
94 keys %$row
95 ) . qq|</table>|;
96 }
97
98 1;

  ViewVC Help
Powered by ViewVC 1.1.26