13 |
|
|
14 |
use lib 'lib'; |
use lib 'lib'; |
15 |
|
|
16 |
extends 'Frey::ClassLoader'; |
extends 'Frey::PPI'; |
17 |
with 'Frey::Web'; |
with 'Frey::Web'; |
18 |
|
|
19 |
has 'class' => ( |
has 'class' => ( |
22 |
required => 1, |
required => 1, |
23 |
); |
); |
24 |
|
|
|
has 'path' => ( |
|
|
is => 'rw', |
|
|
); |
|
|
|
|
25 |
=head2 joose |
=head2 joose |
26 |
|
|
27 |
my $js = $o->joose; |
my $js = $o->joose; |
94 |
my $path = "static/blib/$filename"; |
my $path = "static/blib/$filename"; |
95 |
write_file( $path, $out ); |
write_file( $path, $out ); |
96 |
warn "# created $path\n"; |
warn "# created $path\n"; |
|
$self->path( $path ); |
|
97 |
|
|
98 |
return $out; |
return $out; |
99 |
} |
} |
100 |
|
|
101 |
=head2 methods |
sub as_markup { |
|
|
|
|
my @methods = $o->methods; |
|
|
|
|
|
=cut |
|
|
|
|
|
sub methods { |
|
|
my $self = shift; |
|
|
|
|
|
my ( $meta, $is_role ) = $self->class_meta; |
|
|
|
|
|
my $attr; |
|
|
$attr->{$_}++ foreach $meta->get_attribute_list; |
|
|
my @methods = grep { ! defined($attr->{$_}) } $meta->get_method_list; |
|
|
warn "# methods = ",dump( @methods ) if $self->debug; |
|
|
|
|
|
return sort @methods; |
|
|
} |
|
|
|
|
|
=head1 OUTPUT GENERATION |
|
|
|
|
|
=head2 markup |
|
|
|
|
|
$o->markup; |
|
|
|
|
|
=cut |
|
|
|
|
|
sub markup { |
|
102 |
my ( $self ) = @_; |
my ( $self ) = @_; |
103 |
|
|
104 |
$self->add_head( 'static/introspect.css' ); |
$self->add_head( 'static/introspect.css' ); |
149 |
$name .= qq|<sup title="$role_name">$nr</sup>|; |
$name .= qq|<sup title="$role_name">$nr</sup>|; |
150 |
} |
} |
151 |
qq|<td class="m">$name</td>| |
qq|<td class="m">$name</td>| |
152 |
} $self->methods; |
} $self->class_methods( $class ); |
153 |
|
|
154 |
my @attributes; |
my @attributes; |
155 |
if ( $meta->get_attribute_list ) { |
if ( $meta->get_attribute_list ) { |
156 |
@attributes = map { |
@attributes = map { |
157 |
my $name = $_; |
my $name = $_; |
158 |
my $attr = $meta->get_attribute($name); |
my $attr = $meta->get_attribute($name); |
159 |
|
confess "$class attribute $name isn't blessed ",dump( $attr ) unless blessed $attr; |
160 |
warn "## attr $name ref ",ref( $attr ) if $self->debug; |
warn "## attr $name ref ",ref( $attr ) if $self->debug; |
161 |
my ( $before, $title, $after ) = ( '', '', '' ); |
my ( $before, $title, $after ) = ( '', '', '' ); |
162 |
( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->is_required; |
( $before, $title, $after ) = ( '<b>', ' title="required"', '</b>' ) if $attr->can('is_required') && $attr->is_required; |
163 |
foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref has_default has_trigger has_documentation has_applied_traits/ ) { |
foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref has_default has_trigger has_documentation has_applied_traits/ ) { |
164 |
my $getter; |
my $getter; |
165 |
|
|
166 |
$getter = $check; |
$getter = $check; |
167 |
$getter =~ s/^has_//; |
$getter =~ s/^has_//; |
168 |
|
|
169 |
if ( $attr->$check ) { |
if ( $attr->can($check) && $attr->$check ) { |
170 |
if ( $getter eq $check ) { |
if ( $getter eq $check ) { |
171 |
$after .= "$check"; |
$after .= "$check"; |
172 |
} else { |
} else { |
178 |
} |
} |
179 |
$after .= ' '; |
$after .= ' '; |
180 |
} |
} |
181 |
my $type = $attr->has_type_constraint ? $attr->type_constraint->name : ''; |
my $type = $attr->can('has_type_constraint') && $attr->has_type_constraint ? $attr->type_constraint->name : ''; |
182 |
|
|
183 |
if ( $role_attribute->{$name} ) { |
if ( $role_attribute->{$name} ) { |
184 |
my ( $role_name, $nr ) = each %{ $role_attribute->{$name} }; |
my ( $role_name, $nr ) = each %{ $role_attribute->{$name} }; |
186 |
} |
} |
187 |
|
|
188 |
qq|<td class="a">$before $name</td><td class="t">$type</td><td>$after</td>| |
qq|<td class="a">$before $name</td><td class="t">$type</td><td>$after</td>| |
189 |
} sort $meta->get_attribute_list |
} $meta->get_attribute_list |
190 |
} |
} |
191 |
|
|
192 |
my $table = qq|<table class="frey-introspect"><tr><th class="m">Methods</th><th class="a">Attributes</th><th>Type</th><th class="p">Properties</th></tr>|; |
my $table = qq|<table class="frey-introspect"><tr><th class="m">Methods</th><th class="a">Attributes</th><th>Type</th><th class="p">Properties</th></tr>|; |
198 |
} |
} |
199 |
$table .= qq|</table>|; |
$table .= qq|</table>|; |
200 |
|
|
201 |
my $pod = Frey::Pod->new( class => $class )->markup; |
my $pod = Frey::Pod->new( class => $class )->as_markup; |
202 |
$pod = $pod->{body} if ref($pod); |
$pod = $pod->{body} if ref($pod); |
203 |
|
|
204 |
my $path = $self->class_path( $class ); |
my $path = $self->class_path( $class ); |
217 |
# Spit out the HTML |
# Spit out the HTML |
218 |
my $source = $Highlight->html( $Document ); |
my $source = $Highlight->html( $Document ); |
219 |
|
|
220 |
$source =~ s{(<span.*?line_number.*>\s*)(\d+)(:\s*</span>)}{$1<a href="/editor+$path+$2" title="edit $path +$2" target="editor">$2</a>$3}g; |
$source =~ s{(<span.*?line_number.*>\s*)(\d+)(:\s*</span>)}{$1<a target="editor" href="/editor+$path+$2">$2</a>$3}g; |
221 |
|
|
222 |
# strip page html |
# strip page html |
223 |
# $source =~ s{^.*<body[^>]+>}{}s; |
# $source =~ s{^.*<body[^>]+>}{}s; |
224 |
# $source =~ s{</body.*$}{}s; |
# $source =~ s{</body.*$}{}s; |
225 |
|
|
226 |
|
|
227 |
use Frey::Run; |
my $runnable = join("\n", |
228 |
my $runnable = join("\n", map { qq|<a href="/$class/$_">$_</a>| } grep { $class->can($_) } Frey::Run->runnable ); |
map { |
229 |
|
qq|<a href="/$class/$_">$_</a>| |
230 |
|
} $self->class_runnable( $class ) |
231 |
|
); |
232 |
$runnable = " runnable: $runnable" if $runnable; |
$runnable = " runnable: $runnable" if $runnable; |
233 |
|
|
234 |
my $html = { |
$self->title( $class ); |
|
title => $class, |
|
|
body => join("\n", |
|
|
qq|<h1>$class</h1>|, |
|
|
qq|<div class="frey-introspect">$superclasses\n$roles\n$runnable\n|, |
|
|
$pod ? qq|<a class="frey-skip" href="#___top" title="Skip to POD" >pod</a>| : '', |
|
|
$source ? qq|<a class="frey-skip" href="#source" title="Skip to source" >source</a>| : '', |
|
|
qq|$table\n$pod\n</div>\n|, |
|
|
qq|<h1>Source</h1><a name="source"></a><div class="frey-source">$source</div>|, |
|
|
), |
|
|
}; |
|
235 |
|
|
236 |
return $html; |
my $has_tests = ''; |
237 |
|
if ( my @tests = $self->has_tests ) { |
238 |
|
$has_tests = |
239 |
|
'<br/>test' . ( $#tests > 0 ? 's' : '' ) . ': ' . |
240 |
|
join("\n", map { |
241 |
|
qq|<a target="test" href="/Frey::Test::Runner?tests=$_">$_</a>| |
242 |
|
} @tests ); |
243 |
|
} |
244 |
|
|
245 |
|
return join("\n", |
246 |
|
qq|<h1>$class</h1>|, |
247 |
|
qq|<div class="frey-introspect">$superclasses\n$roles\n$runnable\n|, |
248 |
|
$pod ? qq|<a class="frey-skip" href="#___top" title="Skip to POD" >pod</a>| : '', |
249 |
|
$source ? qq|<a class="frey-skip" href="#source" title="Skip to source" >source</a>| : '', |
250 |
|
$has_tests, |
251 |
|
qq|$table\n$pod\n</div>\n|, |
252 |
|
qq|<h1>Source</h1><a name="source"></a><div class="frey-source">$source</div>|, |
253 |
|
); |
254 |
} |
} |
255 |
|
|
256 |
=head1 SEE ALSO |
=head1 SEE ALSO |