File Coverage

blib/lib/MooseX/TrackDirty/Attributes/Trait/Method/Accessor.pm
Criterion Covered Total %
statement 16 26 61.5
branch 2 4 50.0
condition n/a
subroutine 9 11 81.8
pod n/a
total 27 41 65.8


line stmt bran cond sub pod time code
1             #
2             # This file is part of MooseX-TrackDirty-Attributes
3             #
4             # This software is Copyright (c) 2011 by Chris Weyl.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package MooseX::TrackDirty::Attributes::Trait::Method::Accessor;
11             {
12             $MooseX::TrackDirty::Attributes::Trait::Method::Accessor::VERSION = '1.900'; # TRIAL
13             }
14              
15             # ABSTRACT: Track dirtied attributes
16              
17 11     15   23643 use Moose::Role;
  11         14  
  11         223  
18 11     11   37381 use namespace::autoclean;
  11         19  
  11         84  
19              
20             # debugging
21             #use Smart::Comments '###', '####';
22              
23             sub _generate_original_value_method {
24 2     2   484 my $self = shift;
25 2         21 my $attr = $self->associated_attribute;
26              
27             return sub {
28 6 50   6   1123 confess "Cannot assign a value to a read-only accessor"
        6      
29             if @_ > 1;
30 6         16 $attr->is_dirty_get($_[0]);
31 2         12 };
32             }
33              
34             sub _generate_original_value_method_inline {
35 0     0   0 my $self = shift;
36 0         0 my $attr = $self->associated_attribute;
37              
38             return try {
39 0         0 $self->_compile_code([
40             'sub {',
41             'if (@_ > 1) {',
42             # XXX: this is a hack, but our error stuff is terrible
43             $self->_inline_throw_error(
44             '"Cannot assign a value to a read-only accessor"',
45             'data => \@_'
46             ) . ';',
47             '}',
48             $attr->_inline_is_dirty_get('$_[0]'),
49             '}',
50             ]);
51             }
52 0         0 catch {
53 0         0 confess "Could not generate inline original_value because : $_";
54             };
55             }
56              
57              
58             sub _generate_is_dirty_method {
59 13     13   3499 my $self = shift;
60 13         39 my $attr = $self->associated_attribute;
61              
62             return sub {
63 66 50   66   174130 confess "Cannot assign a value to a read-only accessor"
        6      
        60      
64             if @_ > 1;
65 66         238 $attr->is_dirty_instance($_[0]);
66 13         89 };
67             }
68              
69             sub _generate_is_dirty_method_inline {
70 0     0     my $self = shift;
71 0           my $attr = $self->associated_attribute;
72              
73             return try {
74 0           $self->_compile_code([
75             'sub {',
76             'if (@_ > 1) {',
77             # XXX: this is a hack, but our error stuff is terrible
78             $self->_inline_throw_error(
79             '"Cannot assign a value to a read-only accessor"',
80             'data => \@_'
81             ) . ';',
82             '}',
83             $attr->_inline_is_dirty_instance('$_[0]'),
84             '}',
85             ]);
86             }
87 0           catch {
88 0           confess "Could not generate inline is_dirty because : $_";
89             };
90             }
91              
92             !!42;
93              
94              
95              
96             =pod
97              
98             =encoding utf-8
99              
100             =head1 NAME
101              
102             MooseX::TrackDirty::Attributes::Trait::Method::Accessor - Track dirtied attributes
103              
104             =head1 VERSION
105              
106             This document describes 1.900 of MooseX::TrackDirty::Attributes::Trait::Method::Accessor - released February 15, 2012 as part of MooseX-TrackDirty-Attributes.
107              
108             =head1 DESCRIPTION
109              
110             This is a trait for accessor methods. You really don't need to do anything
111             with it; you want L<MooseX::TrackDirty::Attributes>.
112              
113             =head1 SEE ALSO
114              
115             Please see those modules/websites for more information related to this module.
116              
117             =over 4
118              
119             =item *
120              
121             L<MooseX::TrackDirty::Attributes|MooseX::TrackDirty::Attributes>
122              
123             =item *
124              
125             L<MooseX::TrackDirty::Attributes>
126              
127             =back
128              
129             =head1 SOURCE
130              
131             The development version is on github at L<http://github.com/RsrchBoy/moosex-trackdirty-attributes>
132             and may be cloned from L<git://github.com/RsrchBoy/moosex-trackdirty-attributes.git>
133              
134             =head1 BUGS
135              
136             Please report any bugs or feature requests on the bugtracker website
137             https://github.com/RsrchBoy/moosex-trackdirty-attributes/issues
138              
139             When submitting a bug or request, please include a test-file or a
140             patch to an existing test-file that illustrates the bug or desired
141             feature.
142              
143             =head1 AUTHOR
144              
145             Chris Weyl <cweyl@alumni.drew.edu>
146              
147             =head1 COPYRIGHT AND LICENSE
148              
149             This software is Copyright (c) 2011 by Chris Weyl.
150              
151             This is free software, licensed under:
152              
153             The GNU Lesser General Public License, Version 2.1, February 1999
154              
155             =cut
156              
157              
158             __END__
159