line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Meta::Method::Constructor; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
60
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
359
|
|
4
|
10
|
|
|
10
|
|
60
|
use warnings; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
383
|
|
5
|
10
|
|
|
10
|
|
55
|
use namespace::autoclean; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
101
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
1004
|
use Moose; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
81
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Moose::Meta::Method::Constructor'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
14
|
|
|
|
|
|
|
sub _expected_method_class { |
15
|
0
|
|
|
0
|
|
|
return 'Fey::Object::Table'; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
## no critic (BuiltinFunctions::ProhibitStringyEval, ErrorHandling::RequireCheckingReturnValueOfEval) |
19
|
|
|
|
|
|
|
if ( $Moose::VERSION < 1.9900 ) { |
20
|
|
|
|
|
|
|
eval <<'EOF'; |
21
|
|
|
|
|
|
|
# XXX - This is copied straight from Moose 0.36 because there's no |
22
|
|
|
|
|
|
|
# good way to override it (note the eval it does at the end). |
23
|
|
|
|
|
|
|
sub _initialize_body { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# TODO: |
27
|
|
|
|
|
|
|
# the %options should also include a both |
28
|
|
|
|
|
|
|
# a call 'initializer' and call 'SUPER::' |
29
|
|
|
|
|
|
|
# options, which should cover approx 90% |
30
|
|
|
|
|
|
|
# of the possible use cases (even if it |
31
|
|
|
|
|
|
|
# requires some adaption on the part of |
32
|
|
|
|
|
|
|
# the author, after all, nothing is free) |
33
|
|
|
|
|
|
|
my $source = 'sub {'; |
34
|
|
|
|
|
|
|
$source .= "\n" . 'my $class = shift;'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$source .= "\n" . 'return $class->Moose::Object::new(@_)'; |
37
|
|
|
|
|
|
|
$source |
38
|
|
|
|
|
|
|
.= "\n" |
39
|
|
|
|
|
|
|
. ' if $class ne \'' |
40
|
|
|
|
|
|
|
. $self->associated_metaclass->name . '\';'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$source |
43
|
|
|
|
|
|
|
.= "\n" |
44
|
|
|
|
|
|
|
. 'my $params = ' |
45
|
|
|
|
|
|
|
. $self->_generate_BUILDARGS( '$class', '@_' ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# XXX - override |
48
|
|
|
|
|
|
|
$source .= ";\n" . $self->_inline_search_cache(); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# XXX - override |
51
|
|
|
|
|
|
|
$source .= "\n" . 'my $instance;'; |
52
|
|
|
|
|
|
|
$source .= "\n" . '$class->_ClearConstructorError();'; |
53
|
|
|
|
|
|
|
$source .= "\n" . 'my @args = @_;'; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# XXX - override |
56
|
|
|
|
|
|
|
$source .= "\n" . 'Try::Tiny::try {'; |
57
|
|
|
|
|
|
|
$source .= "\n" . '@_ = @args;'; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# XXX - override |
60
|
|
|
|
|
|
|
$source |
61
|
|
|
|
|
|
|
.= "\n" |
62
|
|
|
|
|
|
|
. '$instance = ' |
63
|
|
|
|
|
|
|
. $self->associated_metaclass()->inline_create_instance('$class'); |
64
|
|
|
|
|
|
|
$source .= ";\n"; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$source .= $self->_generate_params( '$params', '$class' ); |
67
|
|
|
|
|
|
|
$source .= $self->_generate_slot_initializers(); |
68
|
|
|
|
|
|
|
$source .= $self->_generate_triggers(); |
69
|
|
|
|
|
|
|
$source .= ";\n" . $self->_generate_BUILDALL(); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# XXX - override |
72
|
|
|
|
|
|
|
$source .= ";\n" . '}'; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# XXX - override |
75
|
|
|
|
|
|
|
$source .= "\n" . 'Try::Tiny::catch {'; |
76
|
|
|
|
|
|
|
$source .= "\n" |
77
|
|
|
|
|
|
|
. ' die $_ unless Scalar::Util::blessed($_) && $_->isa(q{Fey::Exception::NoSuchRow});'; |
78
|
|
|
|
|
|
|
$source .= "\n" . ' $class->_SetConstructorError($_);'; |
79
|
|
|
|
|
|
|
$source .= "\n" . ' undef $instance;'; |
80
|
|
|
|
|
|
|
$source .= "\n" . '};'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# XXX - override |
83
|
|
|
|
|
|
|
$source .= "\n" . 'return unless $instance;'; |
84
|
|
|
|
|
|
|
$source .= "\n" . $self->_inline_write_to_cache(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$source .= "\n" . 'return $instance;'; |
87
|
|
|
|
|
|
|
$source .= "\n" . '}'; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# XXX - override |
90
|
|
|
|
|
|
|
$source .= "\n"; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
warn $source if $self->options->{debug}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
my $attrs = $self->_attributes; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my @type_constraints |
97
|
|
|
|
|
|
|
= map { $_->can('type_constraint') ? $_->type_constraint : undef } |
98
|
|
|
|
|
|
|
@$attrs; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my @type_constraint_bodies |
101
|
|
|
|
|
|
|
= map { defined $_ ? $_->_compiled_type_constraint : undef; } |
102
|
|
|
|
|
|
|
@type_constraints; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my ( $code, $e ) = $self->_compile_code( |
105
|
|
|
|
|
|
|
code => $source, |
106
|
|
|
|
|
|
|
environment => { |
107
|
|
|
|
|
|
|
'$meta' => \$self, |
108
|
|
|
|
|
|
|
'$metaclass' => \( $self->associated_metaclass ), |
109
|
|
|
|
|
|
|
'$attrs' => \$attrs, |
110
|
|
|
|
|
|
|
'@type_constraints' => \@type_constraints, |
111
|
|
|
|
|
|
|
'@type_constraint_bodies' => \@type_constraint_bodies, |
112
|
|
|
|
|
|
|
}, |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$self->throw_error( |
116
|
|
|
|
|
|
|
"Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e", |
117
|
|
|
|
|
|
|
error => $e, data => $source |
118
|
|
|
|
|
|
|
) if $e; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$self->{'body'} = $code; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _inline_search_cache { |
124
|
|
|
|
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $source = "\n" . 'if ( $metaclass->_object_cache_is_enabled() ) {'; |
127
|
|
|
|
|
|
|
$source |
128
|
|
|
|
|
|
|
.= "\n" . ' my $cached = $metaclass->_search_cache($params);'; |
129
|
|
|
|
|
|
|
$source .= "\n" . ' return $cached if $cached;'; |
130
|
|
|
|
|
|
|
$source .= "\n" . '}'; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _inline_write_to_cache { |
134
|
|
|
|
|
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return "\n" |
137
|
|
|
|
|
|
|
. '$metaclass->_write_to_cache($instance) if $metaclass->_object_cache_is_enabled();'; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
EOF |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else { |
142
|
|
|
|
|
|
|
override _eval_environment => sub { |
143
|
|
|
|
|
|
|
my $self = shift; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $env = super(); |
146
|
|
|
|
|
|
|
$env->{'$metaclass'} = \( $self->associated_metaclass() ); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return $env; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable( inline_constructor => 0 ); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |