506f736414b5667dfbccfb30c2d40b2de9b45e1b
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Meta / Method / Accessor.pm
1 package MooseX::ClassAttribute::Meta::Method::Accessor;
2
3 use strict;
4 use warnings;
5
6 use Moose;
7
8 extends 'Moose::Meta::Method::Accessor';
9
10
11 sub generate_predicate_method_inline
12 {
13     my $attr      = (shift)->associated_attribute;
14     my $attr_name = $attr->name;
15
16     my $code =
17         eval 'sub {'
18         . $attr->associated_class()->inline_is_class_slot_initialized( "'$attr_name'" )
19         . '}';
20
21     confess "Could not generate inline predicate because : $@" if $@;
22
23     return $code;
24 }
25
26 sub generate_clearer_method_inline
27 {
28     my $attr          = (shift)->associated_attribute;
29     my $attr_name     = $attr->name;
30     my $meta_instance = $attr->associated_class->instance_metaclass;
31
32     my $code =
33         eval 'sub {'
34         . $attr->associated_class()->inline_deinitialize_class_slot( "'$attr_name'" )
35         . '}';
36
37     confess "Could not generate inline clearer because : $@" if $@;
38
39     return $code;
40 }
41
42 sub _inline_store
43 {
44     my $self  = shift;
45     shift;
46     my $value = shift;
47
48     my $attr = $self->associated_attribute();
49
50     my $slot_name = sprintf "'%s'", $attr->slots();
51
52     my $meta = $attr->associated_class();
53
54     my $code = $meta->inline_set_class_slot_value($slot_name, $value)    . ";";
55     $code   .= $meta->inline_weaken_class_slot_value($slot_name, $value) . ";"
56         if $attr->is_weak_ref();
57
58     return $code;
59 }
60
61 sub _inline_get
62 {
63     my $self  = shift;
64
65     my $attr = $self->associated_attribute;
66     my $meta = $attr->associated_class();
67
68     my $slot_name = sprintf "'%s'", $attr->slots;
69
70     return $meta->inline_get_class_slot_value($slot_name);
71 }
72
73 sub _inline_access
74 {
75     my $self  = shift;
76
77     my $attr = $self->associated_attribute;
78     my $meta = $attr->associated_class();
79
80     my $slot_name = sprintf "'%s'", $attr->slots;
81
82     return $meta->inline_class_slot_access($slot_name);
83 }
84
85 sub _inline_has
86 {
87     my $self = shift;
88
89     my $attr = $self->associated_attribute;
90     my $meta = $attr->associated_class();
91
92     my $slot_name = sprintf "'%s'", $attr->slots;
93
94     return $meta->inline_is_class_slot_initialized($slot_name);
95 }
96
97 sub _inline_init_slot
98 {
99     my $self = shift;
100
101     return $self->_inline_store( undef, $_[-1] );
102 }
103
104 sub _inline_check_lazy
105 {
106     my $self = shift;
107
108     return
109         $self->SUPER::_inline_check_lazy
110             ( q{'} . $self->associated_attribute()->associated_class()->name() . q{'} );
111 }
112
113 no Moose;
114
115 1;
116