1 |
package Frey::ClassBrowser; |
package Frey::Class::Browser; |
2 |
use Moose; |
use Moose; |
3 |
|
|
4 |
extends 'Frey::ClassLoader'; |
extends 'Frey::ClassLoader'; |
9 |
use Frey::Run; |
use Frey::Run; |
10 |
use Data::Dump qw/dump/; |
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' => ( |
has 'usage_on_top' => ( |
20 |
is => 'rw', |
is => 'rw', |
21 |
isa => 'Bool', |
isa => 'Bool', |
23 |
documentation => 'Show usage on top of list', |
documentation => 'Show usage on top of list', |
24 |
); |
); |
25 |
|
|
26 |
|
our $usage; |
27 |
|
|
28 |
sub as_markup { |
sub as_markup { |
29 |
my $self = shift; |
my $self = shift; |
30 |
my $row; |
my $row; |
31 |
my @icons; |
my @icons; |
32 |
|
|
33 |
my $usage = $self->session_dump( $self->usage ); |
$usage ||= $self->session_dump( $self->usage ); |
34 |
#warn "# usage ",dump( $usage ); |
#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 ) { |
foreach my $class ( $self->classes ) { |
42 |
|
|
43 |
my $icon = ''; |
my $icon = $self->icon_path( $class ); |
|
if ( ! $self->can('icon_path') ) { |
|
|
$self->TODO( "re-apply Frey::Web on $self" ); |
|
|
Frey::Web->meta->apply( $self ); |
|
|
} |
|
|
$icon = $self->icon_path( $class ); |
|
44 |
if ($icon) { |
if ($icon) { |
45 |
push @icons, $icon; |
push @icons, $icon; |
46 |
$icon = qq|<!-- icon:$icon -->|; |
$icon = qq|<!-- icon:$icon -->|; |
90 |
$icons_html->{ $path } || die "can't find $path in ",dump($icons_html); |
$icons_html->{ $path } || die "can't find $path in ",dump($icons_html); |
91 |
}; |
}; |
92 |
|
|
93 |
|
$self->title('Frey'); |
94 |
|
|
95 |
return |
return |
96 |
qq|<table>| . join("\n", |
qq|<table>| . join("\n", |
97 |
map { |
map { |
100 |
$html; |
$html; |
101 |
} |
} |
102 |
sort { |
sort { |
103 |
if ( $usage->{$a} || $usage->{$b} ) { |
if ( $self->usage_sort && ( $usage->{$a} || $usage->{$b} ) ) { |
104 |
$self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b}; |
$self->usage_on_top ? $usage->{$b} <=> $usage->{$a} : $usage->{$a} <=> $usage->{$b}; |
105 |
} else { |
} else { |
106 |
$self->usage_on_top ? $a cmp $b : $b cmp $a; |
$self->usage_on_top ? $a cmp $b : $b cmp $a; |