--- trunk/lib/Frey/Introspect.pm 2008/11/05 08:20:42 269
+++ trunk/lib/Frey/Introspect.pm 2008/11/05 08:21:03 292
@@ -13,7 +13,7 @@
extends 'Frey';
with 'Frey::Web';
-has 'package' => (
+has 'class' => (
is => 'rw',
isa => 'Str',
required => 1,
@@ -32,7 +32,7 @@
sub joose {
my ($self) = @_;
- my ( $meta, $is_role ) = $self->load_package;
+ my ( $meta, $is_role ) = $self->load_class;
if ( ! $is_role ) {
my @superclasses = map{ $_->meta->name }
@@ -42,7 +42,7 @@
my $out;
- my ( $m, $c ) = split(/::/, $self->package, 2);
+ my ( $m, $c ) = split(/::/, $self->class, 2);
my $filename = $m . '.' . ( $c ? "$c." : '' ) . 'js';
$c ||= '';
@@ -77,7 +77,7 @@
$out .= "\t\t},\n\t\tmeta: Frey.HTML,
classMethods: {
renderHTML: function () {
- return new Joose.SimpleRequest().getText(\"/~/" . $self->package . "\")
+ return new Joose.SimpleRequest().getText(\"/" . $self->class . "\")
},\n";
$out .= "\t\t},\n";
@@ -87,7 +87,7 @@
$out =~ s/,\n$/\n/;
$out .= "});\n";
- $out .= "\nconsole.log( 'loaded " . $self->package . " from $filename' );\n";
+ $out .= "\nconsole.log( 'loaded " . $self->class . " from $filename' );\n";
warn "method_list = ",dump( $meta->get_method_list ) if $self->debug;
@@ -109,7 +109,7 @@
sub methods {
my $self = shift;
- my ( $meta, $is_role ) = $self->load_package;
+ my ( $meta, $is_role ) = $self->load_class;
my $attr;
$attr->{$_}++ foreach $meta->get_attribute_list;
@@ -121,9 +121,9 @@
use Frey::ClassLoader;
-sub load_package {
+sub load_class {
my $self = shift;
- return Frey::ClassLoader->load_package( $self->package );
+ return Frey::ClassLoader->load_package( $self->class );
}
@@ -140,9 +140,9 @@
$self->add_head( 'static/introspect.css' );
- my ( $meta, $is_role ) = $self->load_package;
+ my ( $meta, $is_role ) = $self->load_class;
- my $package = $self->package;
+ my $class = $self->class;
my @methods;
@methods = map { qq|
$_ | | } $self->methods;
@@ -154,7 +154,7 @@
my ( $before, $title, $after ) = ( '', '', '' );
( $before, $title, $after ) = ( '', ' title="required"', '' ) if $attr->is_required;
warn $attr->dump(3);
- foreach my $check ( qw/has_type_constraint has_handles is_weak_ref is_required is_lazy should_coerce should_auto_deref 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/ ) {
my $getter;
$getter = $check;
@@ -165,17 +165,19 @@
$after .= "$check";
} else {
$after .= qq{$check};
- $after .= '' . $attr->$getter->dump . '
' if $getter ne $check;
+ # we need dump here instead of $attr->$getter->dump because default can return scalar
+ $after .= '' . dump( $attr->$getter ) . '
' if $getter ne $check;
$after .= '';
}
}
$after .= ' ';
}
- qq|$before $_ | $after | |
+ my $type = $attr->has_type_constraint ? $attr->type_constraint->name : '';
+ qq|$before $_ | $type | $after | |
} sort $meta->get_attribute_list
}
- my $table = qq|Methods | Attributes | Properties |
|;
+ my $table = qq|Methods | Attributes | Type | Properties |
|;
while ( @methods || @attributes ) {
my ($m,$a) = ( shift @methods, shift @attributes );
$m ||= ' | ';
@@ -191,7 +193,7 @@
join(', ',
map {
my $name = $_->meta->name;
- qq|$name| . $_->meta->dump(2) . qq|
|;
+ qq|$name| . $_->meta->dump(2) . qq|
|;
}
#grep { $_ ne 'Moose::Object' }
$meta->superclasses
@@ -201,25 +203,25 @@
if ( $meta->can('roles') ) {
$roles = join(', ',
- grep { ! m/\Q$package\E/ } # skip me
+ grep { ! m/\Q$class\E/ } # skip me
map {
my $name = $_->name;
- qq|$name| . $name->meta->dump(2) . qq|
|;
+ qq|$name| . $name->meta->dump(2) . qq|
|;
}
$meta->calculate_all_roles
);
$roles = " with roles: $roles" if $roles;
}
- my $pod = Frey::Pod->new( class => $package )->markup;
+ my $pod = Frey::Pod->new( class => $class )->markup;
use Frey::Run;
- my $execute = join("\n", map { qq|$_| } grep { $package->can($_) } Frey::Run->execute );
+ my $execute = join("\n", map { qq|$_| } grep { $class->can($_) } Frey::Run->execute );
$execute = " execute: $execute" if $execute;
my $html = $self->page(
- title => "Introspect $package",
- body => qq|$package
|
+ title => "Introspect $class",
+ body => qq|$class
|
. qq|$superclasses\n$roles\n$execute\n|
. ( $pod ? qq|↓pod&darr| : '' )
. qq|$table\n$pod|