--- trunk/lib/Frey/Introspect.pm 2008/07/13 18:01:40 116
+++ trunk/lib/Frey/Introspect.pm 2008/11/19 15:28:23 455
@@ -8,12 +8,15 @@
use File::Slurp;
use List::Util;
+use PPI;
+use PPI::HTML;
+
use lib 'lib';
-extends 'Frey';
+extends 'Frey::ClassLoader';
with 'Frey::Web';
-has 'package' => (
+has 'class' => (
is => 'rw',
isa => 'Str',
required => 1,
@@ -25,14 +28,14 @@
=head2 joose
- my $js = $o->joose( 'Some::Package' );
+ my $js = $o->joose;
=cut
sub joose {
my ($self) = @_;
- my ( $class, $meta, $is_role ) = $self->load_package;
+ my ( $meta, $is_role ) = $self->class_meta;
if ( ! $is_role ) {
my @superclasses = map{ $_->meta->name }
@@ -42,15 +45,17 @@
my $out;
- my ( $m, $c ) = split(/::/, $class->name, 2);
+ my ( $m, $c ) = split(/::/, $self->class, 2);
my $filename = $m . '.' . ( $c ? "$c." : '' ) . 'js';
+ $c ||= '';
+
$out .= "Module(\"$m\", function (m) {\n\tClass(\"$c\", {\n\t\thas: {\n";
- foreach ( $class->get_attribute_list ) {
+ foreach ( $meta->get_attribute_list ) {
$out .= "\t\t\t$_: {\n";
- my $attr = $class->get_attribute($_);
+ my $attr = $meta->get_attribute($_);
my $is = $attr->_is_metadata;
$out .= "\t\t\t\tis: \"$is\",\n" if defined $is;
$out .= "\t\t\t\tlazy: true,\n" if $attr->is_lazy;
@@ -75,7 +80,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";
@@ -85,9 +90,9 @@
$out =~ s/,\n$/\n/;
$out .= "});\n";
- $out .= "\nconsole.log( 'loaded " . $class->name . " from $filename' );\n";
+ $out .= "\nconsole.log( 'loaded " . $self->class . " from $filename' );\n";
- warn "method_list = ",dump( $class->get_method_list ) if $self->debug;
+ warn "method_list = ",dump( $meta->get_method_list ) if $self->debug;
# print $out;
my $path = "static/blib/$filename";
@@ -98,114 +103,149 @@
return $out;
}
-=head2 methods
-
- my @methods = $o->methods;
-
-=cut
-
-sub methods {
- my $self = shift;
-
- my ( $class, $meta, $is_role ) = $self->load_package;
-
- my $attr;
- $attr->{$_}++ foreach $class->get_attribute_list;
- my @methods = grep { ! defined($attr->{$_}) } $class->get_method_list;
- warn "# methods = ",dump( @methods ) if $self->debug;
-
- return @methods;
-}
-
-use Frey::ClassLoader;
-
-sub load_package {
- my $self = shift;
- return Frey::ClassLoader->load_package( $self->package );
-}
-
+sub as_markup {
+ my ( $self ) = @_;
-=head1 OUTPUT GENERATION
+ $self->add_head( 'static/introspect.css' );
-=head2 html
+ my ( $meta, $is_role ) = $self->class_meta;
- $o->html( $request );
+ my $class = $self->class;
-=cut
-
-sub html {
- my ( $self, $request ) = @_;
+ my ( $superclasses, $roles ) = ( 'Role', '' );
+ if ( ! $is_role ) {
+ if ( $meta->superclasses ) {
+ $superclasses = 'Superclasses: ' .
+ join(', ',
+ map {
+ my $name = $_->meta->name;
+ qq|$name| . $_->meta->dump(2) . qq|
|;
+ }
+ #grep { $_ ne 'Moose::Object' }
+ $meta->superclasses
+ );
+ }
+ }
- while (1) {
+ my $role_method;
+ my $role_attribute;
- my $js = $self->head_javascript;
- $js .= << '__END_OF_JS__';
-
-__END_OF_JS__
+ my @attributes;
+ if ( $meta->get_attribute_list ) {
+ @attributes = map {
+ my $name = $_;
+ my $attr = $meta->get_attribute($name);
+ confess "$class attribute $name isn't blessed ",dump( $attr ) unless blessed $attr;
+ warn "## attr $name ref ",ref( $attr ) if $self->debug;
+ my ( $before, $title, $after ) = ( '', '', '' );
+ ( $before, $title, $after ) = ( '', ' title="required"', '' ) if $attr->can('is_required') && $attr->is_required;
+ 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;
+ $getter =~ s/^has_//;
+
+ if ( $attr->can($check) && $attr->$check ) {
+ if ( $getter eq $check ) {
+ $after .= "$check";
+ } else {
+ $after .= qq{$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 .= ' ';
+ }
+ my $type = $attr->can('has_type_constraint') && $attr->has_type_constraint ? $attr->type_constraint->name : '';
- my ( $class, $meta, $is_role ) = $self->load_package;
+ if ( $role_attribute->{$name} ) {
+ my ( $role_name, $nr ) = each %{ $role_attribute->{$name} };
+ $name .= qq|$nr|;
+ }
- my $methods;
- if ( $class->can('meta') ) {
- $methods = dom2html(
- ul => [
- map { (
- li => [ a => { href => '/~/' . $self->package . '/' . $_ } => [ $_ ] ]
- ) } $self->methods
- ]
- );
- $methods = "
Methods | Attributes | Type | Properties | '; + $a ||= ' | '; + $table .= qq| |
---|---|---|---|