Commit | Line | Data |
bb70fe3a |
1 | package MooseX::ClassAttribute::Meta::Method::Accessor; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
eeee5ccb |
6 | our $VERSION = '0.12'; |
f77be127 |
7 | |
67e6eaa5 |
8 | use namespace::autoclean; |
bb70fe3a |
9 | use Moose; |
10 | |
11 | extends 'Moose::Meta::Method::Accessor'; |
12 | |
67e6eaa5 |
13 | sub _generate_predicate_method_inline { |
14 | my $attr = (shift)->associated_attribute; |
bb70fe3a |
15 | |
67e6eaa5 |
16 | my $code |
17 | = eval 'sub {' |
18 | . $attr->associated_class() |
19 | ->inline_is_class_slot_initialized( $attr->name() ) . '}'; |
bb70fe3a |
20 | |
21 | confess "Could not generate inline predicate because : $@" if $@; |
22 | |
23 | return $code; |
24 | } |
25 | |
67e6eaa5 |
26 | sub _generate_clearer_method_inline { |
bb70fe3a |
27 | my $attr = (shift)->associated_attribute; |
bb70fe3a |
28 | my $meta_instance = $attr->associated_class->instance_metaclass; |
29 | |
67e6eaa5 |
30 | my $code |
31 | = eval 'sub {' |
32 | . $attr->associated_class() |
33 | ->inline_deinitialize_class_slot( $attr->name() ) . '}'; |
bb70fe3a |
34 | |
35 | confess "Could not generate inline clearer because : $@" if $@; |
36 | |
37 | return $code; |
38 | } |
39 | |
67e6eaa5 |
40 | sub _inline_store { |
41 | my $self = shift; |
bb70fe3a |
42 | shift; |
43 | my $value = shift; |
44 | |
45 | my $attr = $self->associated_attribute(); |
46 | |
bb70fe3a |
47 | my $meta = $attr->associated_class(); |
48 | |
67e6eaa5 |
49 | my $code |
50 | = $meta->inline_set_class_slot_value( $attr->slots(), $value ) . ";"; |
51 | $code |
52 | .= $meta->inline_weaken_class_slot_value( $attr->slots(), $value ) |
53 | . ";" |
bb70fe3a |
54 | if $attr->is_weak_ref(); |
55 | |
56 | return $code; |
57 | } |
58 | |
67e6eaa5 |
59 | sub _inline_get { |
60 | my $self = shift; |
bb70fe3a |
61 | |
62 | my $attr = $self->associated_attribute; |
63 | my $meta = $attr->associated_class(); |
64 | |
7aab7f6c |
65 | return $meta->inline_get_class_slot_value( $attr->slots() ); |
bb70fe3a |
66 | } |
67 | |
67e6eaa5 |
68 | sub _inline_access { |
69 | my $self = shift; |
bb70fe3a |
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 | |
67e6eaa5 |
77 | sub _inline_has { |
bb70fe3a |
78 | my $self = shift; |
79 | |
80 | my $attr = $self->associated_attribute; |
81 | my $meta = $attr->associated_class(); |
82 | |
7aab7f6c |
83 | return $meta->inline_is_class_slot_initialized( $attr->slots() ); |
bb70fe3a |
84 | } |
85 | |
67e6eaa5 |
86 | sub _inline_init_slot { |
bb70fe3a |
87 | my $self = shift; |
88 | |
89 | return $self->_inline_store( undef, $_[-1] ); |
90 | } |
91 | |
67e6eaa5 |
92 | sub _inline_check_lazy { |
bb70fe3a |
93 | my $self = shift; |
94 | |
67e6eaa5 |
95 | return $self->SUPER::_inline_check_lazy( q{'} |
96 | . $self->associated_attribute()->associated_class()->name() |
97 | . q{'} ); |
bb70fe3a |
98 | } |
99 | |
67e6eaa5 |
100 | sub _inline_get_old_value_for_trigger { |
8207dfe7 |
101 | my $self = shift; |
102 | |
103 | my $attr = $self->associated_attribute(); |
104 | return '' unless $attr->has_trigger(); |
105 | |
67e6eaa5 |
106 | my $pred = $attr->associated_class() |
107 | ->inline_is_class_slot_initialized( $attr->name() ); |
8207dfe7 |
108 | |
109 | return |
67e6eaa5 |
110 | 'my @old = ' |
8207dfe7 |
111 | . $pred . q{ ? } |
67e6eaa5 |
112 | . $self->_inline_get() |
113 | . q{ : ()} . ";\n"; |
8207dfe7 |
114 | |
115 | } |
116 | |
bb70fe3a |
117 | 1; |
118 | |
a1c01f67 |
119 | __END__ |
120 | |
7a4a3b1e |
121 | =pod |
122 | |
123 | =head1 NAME |
124 | |
125 | MooseX::ClassAttribute::Meta::Method::Accessor - Accessor method generation for class attributes |
126 | |
127 | =head1 DESCRIPTION |
128 | |
129 | This class overrides L<Moose::Meta::Method::Accessor> to do code |
130 | generation properly for class attributes. |
131 | |
132 | =head1 AUTHOR |
133 | |
134 | Dave Rolsky, C<< <autarch@urth.org> >> |
135 | |
136 | =head1 BUGS |
137 | |
138 | See L<MooseX::ClassAttribute> for details. |
139 | |
140 | =head1 COPYRIGHT & LICENSE |
141 | |
0cee5df4 |
142 | Copyright 2007-2010 Dave Rolsky, All Rights Reserved. |
7a4a3b1e |
143 | |
144 | This program is free software; you can redistribute it and/or modify |
145 | it under the same terms as Perl itself. |
146 | |
147 | =cut |