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

Contents of /trunk/lib/Frey/Class/Browser.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 795 - (show annotations)
Wed Dec 10 17:57:10 2008 UTC (15 years, 4 months ago) by dpavlin
File size: 2524 byte(s)
make usage sort optional
1 package Frey::Class::Browser;
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_sort' => (
13 is => 'rw',
14 isa => 'Bool',
15 default => 0,
16 documentation => 'Sort by class usage',
17 );
18
19 has 'usage_on_top' => (
20 is => 'rw',
21 isa => 'Bool',
22 default => 1,
23 documentation => 'Show usage on top of list',
24 );
25
26 our $usage;
27
28 sub as_markup {
29 my $self = shift;
30 my $row;
31 my @icons;
32
33 $usage ||= $self->session_dump( $self->usage );
34 #warn "# usage ",dump( $usage );
35
36 if ( ! $self->can('icon_path') ) {
37 $self->TODO( "re-apply Frey::Web on $self" );
38 Frey::Web->meta->apply( $self );
39 }
40
41 foreach my $class ( $self->classes ) {
42
43 my $icon = $self->icon_path( $class );
44 if ($icon) {
45 push @icons, $icon;
46 $icon = qq|<!-- icon:$icon -->|;
47 } else {
48 $icon = '';
49 }
50
51 my $html
52 = qq|<tr><td>$icon</td><td><a target="$class" href="/$class" title="|
53 . $self->class_path( $class )
54 . qq|">$class</a></td><td>|
55 ;
56 if ( $class->can('meta') ) {
57 if ( $class->meta->isa('Moose::Meta::Role') ) {
58 $html .= qq|role|;
59 } else {
60 $html .= qq|<a target="$class" href="/Frey-ObjectDesigner?class=$class">design</a>| if $class->can('collection');
61 }
62 }
63
64 my @run = map {
65 my $invoke = $_;
66 s{^as_}{};
67 s{_as_\w+}{};
68 qq|<a target="$class" href="/$class/$invoke" title="$class->$invoke">$_</a>|;
69 } $self->class_runnable( $class );
70 push @run, qq|<a target="$class" href="/Frey-ObjectBrowser?class=$class">collection</a>| if $class->can('collection_table');
71
72 my @inputs = $self->class_inputs( $class );
73
74 $usage->{$class} ||= 0;
75 $html
76 .= qq|</td><td>|
77 . join(' ', @run)
78 . qq|</td><td>|
79 . ( @inputs ? '&larr; ' . join(' ', @inputs) : '' )
80 . qq|</td><td>|
81 . ( $usage->{$class} || '' )
82 . qq|</td></tr>|
83 ;
84 $row->{$class} = $html;
85 }
86
87 my $icons_html = $self->combine_images( @icons );
88 sub icon {
89 my ($icons_html,$path) = @_;
90 $icons_html->{ $path } || die "can't find $path in ",dump($icons_html);
91 };
92
93 $self->title('Frey');
94
95 return
96 qq|<table>| . join("\n",
97 map {
98 my $html = $row->{$_};
99 $html =~ s{<!-- icon:(\S+) -->}{icon($icons_html,$1)}gse;
100 $html;
101 }
102 sort {
103 if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) {
104 $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b};
105 } else {
106 $self->usage_on_top ? $a cmp $b : $b cmp $a;
107 }
108 }
109 keys %$row
110 ) . qq|</table>|;
111 }
112
113 1;

  ViewVC Help
Powered by ViewVC 1.1.26