22 |
|
|
23 |
my $package = $self->package; |
my $package = $self->package; |
24 |
|
|
25 |
#intercept role application so we can accurately generate |
#intercept role application so we can accurately generate |
26 |
#method and attribute information for the parent class. |
#method and attribute information for the parent class. |
27 |
#this is fragile, but there is not better way that i am aware of |
#this is fragile, but there is not better way that i am aware of |
28 |
my $rmeta = Moose::Meta::Role->meta; |
my $rmeta = Moose::Meta::Role->meta; |
29 |
$rmeta->make_mutable if $rmeta->is_immutable; |
$rmeta->make_mutable if $rmeta->is_immutable; |
30 |
my $original_apply = $rmeta->get_method("apply")->body; |
my $original_apply = $rmeta->get_method("apply")->body; |
31 |
$rmeta->remove_method("apply"); |
$rmeta->remove_method("apply"); |
32 |
my @roles_to_apply; |
my @roles_to_apply; |
33 |
$rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])}); |
$rmeta->add_method("apply", sub{push(@roles_to_apply, [@_])}); |
34 |
#load the package with the hacked Moose::Meta::Role |
#load the package with the hacked Moose::Meta::Role |
35 |
eval { Class::MOP::load_class($package); }; |
eval { Class::MOP::load_class($package); }; |
36 |
confess "Failed to load package ${package} $@" if $@; |
confess "Failed to load package ${package} $@" if $@; |
37 |
|
|
38 |
#get on with analyzing the package |
#get on with analyzing the package |
39 |
my $meta = $package->meta; |
my $meta = $package->meta; |
40 |
my $spec = {}; |
my $spec = {}; |
41 |
my ($class, $is_role); |
my ($class, $is_role); |
42 |
if($package->meta->isa('Moose::Meta::Role')){ |
if($package->meta->isa('Moose::Meta::Role')){ |
43 |
$is_role = 1; |
$is_role = 1; |
44 |
# we need to apply the role to a class to be able to properly introspect it |
# we need to apply the role to a class to be able to properly introspect it |
45 |
$class = Moose::Meta::Class->create_anon_class; |
$class = Moose::Meta::Class->create_anon_class; |
46 |
$original_apply->($meta, $class); |
$original_apply->($meta, $class); |
47 |
} else { |
} else { |
48 |
#roles don't have superclasses ... |
#roles don't have superclasses ... |
49 |
$class = $meta; |
$class = $meta; |
50 |
my @superclasses = map{ $_->meta } |
my @superclasses = map{ $_->meta->name } |
51 |
grep { $_ ne 'Moose::Object' } $meta->superclasses; |
grep { $_ ne 'Moose::Object' } $meta->superclasses; |
52 |
warn "superclasses ",dump( @superclasses ); |
warn "superclasses ",dump( @superclasses ); |
53 |
} |
} |
54 |
|
|
55 |
my $out; |
my $out; |
56 |
|
|
62 |
foreach ( $class->get_attribute_list ) { |
foreach ( $class->get_attribute_list ) { |
63 |
$out .= "\t\t\t$_: {\n"; |
$out .= "\t\t\t$_: {\n"; |
64 |
|
|
65 |
|
my $attr = $class->get_attribute($_); |
66 |
|
my $is = $attr->_is_metadata; |
67 |
|
$out .= "\t\t\t\tis: \"$is\",\n" if defined $is; |
68 |
|
$out .= "\t\t\t\tlazy: true,\n" if $attr->is_lazy; |
69 |
|
$out .= "\t\t\t\trequired: true,\n" if $attr->is_required; |
70 |
|
$out .= "\t\t\t\tinit: \"" . $attr->init_arg . "\",\n" if $attr->init_arg; # FIXME |
71 |
|
|
72 |
|
if( defined(my $isa = $attr->_isa_metadata) ){ |
73 |
|
if( blessed $isa ){ |
74 |
|
while( blessed $isa ){ |
75 |
|
$isa = $isa->name; |
76 |
|
} |
77 |
|
} |
78 |
|
$isa =~ s/\s+\|\s+undef//gi; |
79 |
|
$out .= "\t\t\t\tisa: Moose.$isa,\n"; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
$out .= "\t\t\t},\n"; |
$out .= "\t\t\t},\n"; |
84 |
|
|
85 |
} |
} |
87 |
$out .= "\t\t},\n"; |
$out .= "\t\t},\n"; |
88 |
|
|
89 |
$out .= "\t}),\n"; |
$out .= "\t}),\n"; |
90 |
|
|
91 |
|
$out =~ s/,\n$/\n/; |
92 |
$out .= "});\n"; |
$out .= "});\n"; |
93 |
|
|
94 |
$out .= "\nconsole.log( 'loaded " . $class->name . " from $filename' );\n"; |
$out .= "\nconsole.log( 'loaded " . $class->name . " from $filename' );\n"; |