line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package MooseX::Compile::Bootstrap; |
4
|
1
|
|
|
1
|
|
1120
|
use base qw(MooseX::Compile::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
|
|
|
|
|
|
use warnings; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use constant DEBUG => MooseX::Compile::Base::DEBUG(); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %known_pmc_files; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub import { |
14
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$self->check_version(%args); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$known_pmc_files{$args{file}} = 1; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub load_cached_meta { |
22
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
23
|
|
|
|
|
|
|
my ( $class, $file ) = @args{qw(class file)}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $t = times; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
warn "loading metaclass for class '$class' from cached file\n" if DEBUG; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $meta = $self->inflate_cached_meta( |
30
|
|
|
|
|
|
|
$self->load_raw_cached_meta(%args), |
31
|
|
|
|
|
|
|
%args, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
no strict 'refs'; |
36
|
|
|
|
|
|
|
no warnings 'redefine'; |
37
|
|
|
|
|
|
|
*{ "${class}::meta" } = sub { $meta }; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
warn "registering loaded metaclass '$meta' for class '$class', loaded in " . (times - $t) . "s\n" if DEBUG; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Class::MOP::store_metaclass_by_name($class, $meta); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub inflate_cached_meta { |
46
|
|
|
|
|
|
|
my ( $self, $meta, %args ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$Class::Autouse::DEBUG = 1; |
49
|
|
|
|
|
|
|
#require Class::Autouse; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
foreach my $class qw( |
52
|
|
|
|
|
|
|
Moose::Meta::Class |
53
|
|
|
|
|
|
|
Moose::Meta::Instance |
54
|
|
|
|
|
|
|
Moose::Meta::TypeConstraint |
55
|
|
|
|
|
|
|
Moose::Meta::TypeCoercion |
56
|
|
|
|
|
|
|
Moose::Meta::Attribute |
57
|
|
|
|
|
|
|
) { |
58
|
|
|
|
|
|
|
#warn "marking $class for autouse\n" if DEBUG; |
59
|
|
|
|
|
|
|
#Class::Autouse->autouse($class); |
60
|
|
|
|
|
|
|
$self->load_classes($class); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->create_visitor(%args)->visit($meta); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub create_visitor { |
67
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
require Data::Visitor::Callback; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Data::Visitor::Callback->new( |
72
|
|
|
|
|
|
|
object_no_class => "visit_ref", |
73
|
|
|
|
|
|
|
object_final => sub { |
74
|
|
|
|
|
|
|
my ( $v, $obj ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
die "Invalid object loaded from cached meta: $obj" |
77
|
|
|
|
|
|
|
if ref($obj) =~ /^MooseX::Compile::/; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
unless ( ref($obj) =~ /^Class::MOP::Class::__ANON__::/x ) { |
80
|
|
|
|
|
|
|
#warn "marking " . ref($obj) . " for autouse\n" if DEBUG; |
81
|
|
|
|
|
|
|
#Class::Autouse->autouse(ref($obj)); |
82
|
|
|
|
|
|
|
$self->load_classes(ref($obj)); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $obj; |
86
|
|
|
|
|
|
|
}, |
87
|
|
|
|
|
|
|
"MooseX::Compile::mangled::immutable_metaclass" => sub { |
88
|
|
|
|
|
|
|
my ( $v, $spec ) = @_; |
89
|
|
|
|
|
|
|
my ( $class, $options ) = @{ $spec }{qw(class options)}; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$class = $v->visit_ref($class); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
require Class::MOP::Immutable; |
94
|
|
|
|
|
|
|
my $t = Class::MOP::Immutable->new( $class, $options ); |
95
|
|
|
|
|
|
|
my $new_metaclass = $t->create_immutable_metaclass; |
96
|
|
|
|
|
|
|
bless $class, $new_metaclass->name; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
warn "recreated immutable metaclass for " . $class->name . " as " . $new_metaclass->name . "\n" if DEBUG; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
return $class; |
101
|
|
|
|
|
|
|
}, |
102
|
|
|
|
|
|
|
"MooseX::Compile::mangled::constraint" => sub { |
103
|
|
|
|
|
|
|
my ( $v, $sym ) = @_; |
104
|
|
|
|
|
|
|
warn "loading type constraint named '$sym->{name}' in cached metaclass\n" if DEBUG; |
105
|
|
|
|
|
|
|
require Moose::Util::TypeConstraints; |
106
|
|
|
|
|
|
|
Moose::Util::TypeConstraints::find_type_constraint($sym->{name}); |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
"MooseX::Compile::mangled::subref" => sub { |
109
|
|
|
|
|
|
|
my ( $v, $sym ) = @_; |
110
|
|
|
|
|
|
|
no strict 'refs'; |
111
|
|
|
|
|
|
|
if ( my $file = $sym->{file} ) { |
112
|
|
|
|
|
|
|
warn "loading file $sym->{file} for the definition of \&$sym->{name}\n" if DEBUG && !exists($INC{$sym->{file}}); |
113
|
|
|
|
|
|
|
require $file; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
\&{ $sym->{name} }; |
116
|
|
|
|
|
|
|
}, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub load_raw_cached_meta { |
121
|
|
|
|
|
|
|
my ( $self, %args ) = @_; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $meta_file = $self->cached_meta_file(%args); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
require Storable; |
126
|
|
|
|
|
|
|
Storable::retrieve($meta_file); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__PACKAGE__ |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=pod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 NAME |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
MooseX::Compile::Bootstrap - Helps L<Moose> C<.pmc> files load. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 SYNOPSIS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# no user servicable parts inside |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 HERE BE DRAGONS |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This is alpha code. You can tinker, subclass etc but beware that things |
147
|
|
|
|
|
|
|
definitely will change in the near future. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
When a final version comes out there will be a documented process for how to |
150
|
|
|
|
|
|
|
extend the bootstrapper to handle your classes, whether by subclassing or using |
151
|
|
|
|
|
|
|
various hooks. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
In the future this file will also live in its own distribution so that you can |
154
|
|
|
|
|
|
|
deploy compiled C<.pmc> files without ever needing to install L<Moose> on your |
155
|
|
|
|
|
|
|
target machine. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |