Meta/Method/Constructor.pm

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