--- trunk/lib/Frey/Introspect.pm 2008/07/02 21:10:57 49 +++ trunk/lib/Frey/Introspect.pm 2008/07/02 22:30:19 50 @@ -22,35 +22,35 @@ my $package = $self->package; - #intercept role application so we can accurately generate - #method and attribute information for the parent class. - #this is fragile, but there is not better way that i am aware of - my $rmeta = Moose::Meta::Role->meta; - $rmeta->make_mutable if $rmeta->is_immutable; - my $original_apply = $rmeta->get_method("apply")->body; - $rmeta->remove_method("apply"); - my @roles_to_apply; - $rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])}); - #load the package with the hacked Moose::Meta::Role - 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; - # we need to apply the role to a class to be able to properly introspect it - $class = Moose::Meta::Class->create_anon_class; - $original_apply->($meta, $class); - } else { - #roles don't have superclasses ... - $class = $meta; - my @superclasses = map{ $_->meta } - grep { $_ ne 'Moose::Object' } $meta->superclasses; - warn "superclasses ",dump( @superclasses ); - } + #intercept role application so we can accurately generate + #method and attribute information for the parent class. + #this is fragile, but there is not better way that i am aware of + my $rmeta = Moose::Meta::Role->meta; + $rmeta->make_mutable if $rmeta->is_immutable; + my $original_apply = $rmeta->get_method("apply")->body; + $rmeta->remove_method("apply"); + my @roles_to_apply; + $rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])}); + #load the package with the hacked Moose::Meta::Role + 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; + # we need to apply the role to a class to be able to properly introspect it + $class = Moose::Meta::Class->create_anon_class; + $original_apply->($meta, $class); + } else { + #roles don't have superclasses ... + $class = $meta; + my @superclasses = map{ $_->meta->name } + grep { $_ ne 'Moose::Object' } $meta->superclasses; + warn "superclasses ",dump( @superclasses ); + } my $out; @@ -62,6 +62,24 @@ foreach ( $class->get_attribute_list ) { $out .= "\t\t\t$_: {\n"; + my $attr = $class->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; + $out .= "\t\t\t\trequired: true,\n" if $attr->is_required; + $out .= "\t\t\t\tinit: \"" . $attr->init_arg . "\",\n" if $attr->init_arg; # FIXME + + if( defined(my $isa = $attr->_isa_metadata) ){ + if( blessed $isa ){ + while( blessed $isa ){ + $isa = $isa->name; + } + } + $isa =~ s/\s+\|\s+undef//gi; + $out .= "\t\t\t\tisa: Moose.$isa,\n"; + } + + $out .= "\t\t\t},\n"; } @@ -69,6 +87,8 @@ $out .= "\t\t},\n"; $out .= "\t}),\n"; + + $out =~ s/,\n$/\n/; $out .= "});\n"; $out .= "\nconsole.log( 'loaded " . $class->name . " from $filename' );\n";