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