--- trunk/lib/Frey/ClassBrowser.pm 2008/11/05 08:20:52 279 +++ trunk/lib/Frey/ClassBrowser.pm 2008/12/10 17:51:29 793 @@ -1,35 +1,106 @@ -package Frey::ClassBrowser; +package Frey::Class::Browser; use Moose; -extends 'Frey'; +extends 'Frey::ClassLoader'; +with 'Frey::Web'; +with 'Frey::Session'; +with 'Frey::Web::CombineImages'; -use Frey::ClassLoader; use Frey::Run; +use Data::Dump qw/dump/; -our $markup; +has 'usage_on_top' => ( + is => 'rw', + isa => 'Bool', + default => 1, + documentation => 'Show usage on top of list', +); -sub markup { - return $markup if $markup; - my $f = Frey::ClassLoader->new; - my $html; - foreach my $package ( $f->classes ) { - $html .= qq|$package|; - if ( $package->can('meta') ) { - if ( $package->meta->isa('Moose::Meta::Role') ) { +our $usage; + +sub as_markup { + my $self = shift; + my $row; + my @icons; + + $usage ||= $self->session_dump( $self->usage ); + #warn "# usage ",dump( $usage ); + + if ( ! $self->can('icon_path') ) { + $self->TODO( "re-apply Frey::Web on $self" ); + Frey::Web->meta->apply( $self ); + } + + foreach my $class ( $self->classes ) { + + my $icon = $self->icon_path( $class ); + if ($icon) { + push @icons, $icon; + $icon = qq||; + } else { + $icon = ''; + } + + my $html + = qq|$icon$class| + ; + if ( $class->can('meta') ) { + if ( $class->meta->isa('Moose::Meta::Role') ) { $html .= qq|role|; } else { - $html .= qq|design| if $package->can('collection'); + $html .= qq|design| if $class->can('collection'); } } - my @inspect; - push @inspect, qq|collection| if $package->can('collection_table'); - foreach my $try ( Frey::Run->execute ) { - push @inspect, qq|$try| if $package->can($try); - } - $html .= qq|| . join(' ', @inspect) . qq||; + + my @run = map { + my $invoke = $_; + s{^as_}{}; + s{_as_\w+}{}; + qq|$_|; + } $self->class_runnable( $class ); + push @run, qq|collection| if $class->can('collection_table'); + + my @inputs = $self->class_inputs( $class ); + + $usage->{$class} ||= 0; + $html + .= qq|| + . join(' ', @run) + . qq|| + . ( @inputs ? '← ' . join(' ', @inputs) : '' ) + . qq|| + . ( $usage->{$class} || '' ) + . qq|| + ; + $row->{$class} = $html; } - $html = "$html
" if $html; - $markup = $html; + + my $icons_html = $self->combine_images( @icons ); + sub icon { + my ($icons_html,$path) = @_; + $icons_html->{ $path } || die "can't find $path in ",dump($icons_html); + }; + + $self->title('Frey'); + + return + qq|| . join("\n", + map { + my $html = $row->{$_}; + $html =~ s{}{icon($icons_html,$1)}gse; + $html; + } + sort { + if ( $usage->{$a} || $usage->{$b} ) { + $self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b}; + } else { + $self->usage_on_top ? $a cmp $b : $b cmp $a; + } + } + keys %$row + ) . qq|
|; } 1;