pass bare names and quote them closer to the code generation
[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
15     my $code =
16         eval 'sub {'
17         . $attr->associated_class()->inline_is_class_slot_initialized( $attr->name() )
18         . '}';
19
20     confess "Could not generate inline predicate because : $@" if $@;
21
22     return $code;
23 }
24
25 sub generate_clearer_method_inline
26 {
27     my $attr          = (shift)->associated_attribute;
28     my $meta_instance = $attr->associated_class->instance_metaclass;
29
30     my $code =
31         eval 'sub {'
32         . $attr->associated_class()->inline_deinitialize_class_slot( $attr->name() )
33         . '}';
34
35     confess "Could not generate inline clearer because : $@" if $@;
36
37     return $code;
38 }
39
40 sub _inline_store
41 {
42     my $self  = shift;
43     shift;
44     my $value = shift;
45
46     my $attr = $self->associated_attribute();
47
48     my $meta = $attr->associated_class();
49
50     my $code = $meta->inline_set_class_slot_value( $attr->slots(), $value )    . ";";
51     $code   .= $meta->inline_weaken_class_slot_value( $attr->slots(), $value ) . ";"
52         if $attr->is_weak_ref();
53
54     return $code;
55 }
56
57 sub _inline_get
58 {
59     my $self  = shift;
60
61     my $attr = $self->associated_attribute;
62     my $meta = $attr->associated_class();
63
64     return $meta->inline_get_class_slot_value( $attr->slots() );
65 }
66
67 sub _inline_access
68 {
69     my $self  = shift;
70
71     my $attr = $self->associated_attribute;
72     my $meta = $attr->associated_class();
73
74     return $meta->inline_class_slot_access( $attr->slots() );
75 }
76
77 sub _inline_has
78 {
79     my $self = shift;
80
81     my $attr = $self->associated_attribute;
82     my $meta = $attr->associated_class();
83
84     return $meta->inline_is_class_slot_initialized( $attr->slots() );
85 }
86
87 sub _inline_init_slot
88 {
89     my $self = shift;
90
91     return $self->_inline_store( undef, $_[-1] );
92 }
93
94 sub _inline_check_lazy
95 {
96     my $self = shift;
97
98     return
99         $self->SUPER::_inline_check_lazy
100             ( q{'} . $self->associated_attribute()->associated_class()->name() . q{'} );
101 }
102
103 no Moose;
104
105 1;
106
107 =pod
108
109 =head1 NAME
110
111 MooseX::ClassAttribute::Meta::Method::Accessor - Accessor method generation for class attributes
112
113 =head1 DESCRIPTION
114
115 This class overrides L<Moose::Meta::Method::Accessor> to do code
116 generation properly for class attributes.
117
118 =head1 AUTHOR
119
120 Dave Rolsky, C<< <autarch@urth.org> >>
121
122 =head1 BUGS
123
124 See L<MooseX::ClassAttribute> for details.
125
126 =head1 COPYRIGHT & LICENSE
127
128 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
129
130 This program is free software; you can redistribute it and/or modify
131 it under the same terms as Perl itself.
132
133 =cut