--- trunk/lib/Frey/Introspect.pm 2008/07/05 15:08:51 52
+++ trunk/lib/Frey/Introspect.pm 2008/07/05 15:19:55 53
@@ -10,6 +10,8 @@
use File::Slurp;
use List::Util;
+use Continuity::Widget::DomNode;
+
extends 'Frey';
has 'package' => (
@@ -18,23 +20,18 @@
required => 1,
);
-has 'renderHTML' => (
- is => 'rw',
- isa => 'Str',
-);
-
has 'path' => (
is => 'rw',
);
-=head2 examine
+=head2 load_package
- my $js = $o->examine( 'Some::Package' );
+ my ( $class, $meta, $is_role ) = $o->load_package( 'Some::Package' );
=cut
-sub examine {
- my ($self) = @_;
+sub load_package {
+ my ( $self ) = @_;
my $package = $self->package;
@@ -51,9 +48,8 @@
eval { Class::MOP::load_class($package); };
confess "Failed to load package ${package} $@" if $@;
- #get on with analyzing the package
my $meta = $package->meta;
- my $spec = {};
+
my ($class, $is_role);
if($package->meta->isa('Moose::Meta::Role')){
$is_role = 1;
@@ -63,6 +59,22 @@
} else {
#roles don't have superclasses ...
$class = $meta;
+ }
+ return ( $class, $meta, $is_role );
+}
+
+=head2 joose
+
+ my $js = $o->joose( 'Some::Package' );
+
+=cut
+
+sub joose {
+ my ($self) = @_;
+
+ my ( $class, $meta, $is_role ) = $self->load_package;
+
+ if ( ! $is_role ) {
my @superclasses = map{ $_->meta->name }
grep { $_ ne 'Moose::Object' } $meta->superclasses;
warn "superclasses ",dump( @superclasses );
@@ -103,7 +115,7 @@
$out .= "\t\t},\n\t\tmeta: Frey.HTML,
classMethods: {
renderHTML: function () {
- return new Joose.SimpleRequest().getText(\"json?class=$c\")
+ return new Joose.SimpleRequest().getText(\"inspect?module=$m;class=$c\")
},\n";
$out .= "\t\t},\n";
@@ -117,11 +129,6 @@
warn $class->dump(2);
- my $attr;
- $attr->{$_}++ foreach $class->get_attribute_list;
- my @methods = grep { ! defined($attr->{$_}) } $class->get_method_list;
- warn "methods = ",dump( @methods );
-
warn "method_list = ",dump( $class->get_method_list );
warn dump( map{ $class->get_method($_)->name } sort $class->get_method_list );
@@ -134,6 +141,84 @@
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 );
+
+ return @methods;
+}
+
+=head1 OUTPUT GENERATION
+
+=head2 html
+
+ $o->html( $request );
+
+=cut
+
+our @javascript = ( qw'
+../lib/Joose.js
+');
+
+sub html {
+ my ( $self, $request ) = @_;
+
+ while (1) {
+
+ my $js = [ map {
+ ( script => { type => 'text/javascript', src => $_ } )
+ } @javascript ];
+ warn "# js = ",dump( $js );
+
+ my $o;
+
+ my ( $class, $meta, $is_role ) = $self->load_package();
+ if ( $class->can('meta') ) {
+ $o = Continuity::Widget::DomNode->create(
+ ul => [
+ map { (
+ li => [ a => { href => $_ } => [ $_ ] ]
+ ) } $self->methods
+ ]
+ )->to_string;
+ } else {
+ $o = 'not introspectable';
+ }
+
+ warn "# o = ",dump( $o );
+
+ my $doc = Continuity::Widget::DomNode->create(
+ html => [
+ head => [
+ link => { rel=>"stylesheet", href=>"/static/app.css", type=>"text/css", media=>"screen" },
+# $js,
+ ],
+ body => [
+ h1 => [ 'Introspect ', $self->package ],
+ $o,
+ ],
+ ]
+ );
+
+ $request->print($doc->to_string);
+ warn "# html = ", $doc->to_string;
+ $request->next;
+ }
+ warn "# exit html";
+}
+
=head1 SEE ALSO
L on which this code is based