File Coverage

blib/lib/MooseX/TrackDirty/Attributes.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


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;
11             {
12             $MooseX::TrackDirty::Attributes::VERSION = '1.900'; # TRIAL
13             }
14              
15             # ABSTRACT: Track dirtied attributes
16              
17 10     10   3036071 use warnings;
  10         20  
  10         292  
18 10     10   34 use strict;
  10         14  
  10         200  
19              
20 10     10   30 use Moose 2.0 ();
  10         235  
  10         148  
21 10     10   4007 use namespace::autoclean;
  10         58749  
  10         34  
22 10     10   429 use Moose::Exporter;
  10         15  
  10         66  
23              
24             Moose::Exporter->setup_import_methods(
25             trait_aliases => [
26             [ 'MooseX::TrackDirty::Attributes::Trait::Attribute' => 'TrackDirty' ],
27             ],
28             );
29              
30             !!42;
31              
32              
33              
34             =pod
35              
36             =encoding utf-8
37              
38             =head1 NAME
39              
40             MooseX::TrackDirty::Attributes - Track dirtied attributes
41              
42             =head1 VERSION
43              
44             This document describes 1.900 of MooseX::TrackDirty::Attributes - released February 15, 2012 as part of MooseX-TrackDirty-Attributes.
45              
46             =head1 SYNOPSIS
47              
48             package Foo;
49             use Moose;
50             use MooseX::TrackDirty::Attributes;
51              
52             # tracking accessor is not automagically applied
53             has foo => (is => 'rw');
54              
55             # one_is_dirty() is generated by default
56             has one => (traits => [ TrackDirty ], is => 'rw');
57              
58             # dirtyness "accessor" is generated as two_isnt_clean()
59             has two => (
60             traits => [ TrackDirty ],
61             is => 'rw',
62             is_dirty => 'two_isnt_clean',
63             );
64              
65             # three_is_dirty() and original_value_of_three() are generated
66             has three => (
67             traits => [ TrackDirty ],
68             is => 'rw',
69             original_value => 'original_value_of_three',
70             );
71              
72             # ...meanwhile, at the bat-cave
73              
74             package main;
75             my $foo = Foo->new();
76              
77             $foo->one_is_dirty; # false
78              
79             =head1 DESCRIPTION
80              
81             MooseX::TrackDirty::Attributes does the necessary metaclass fiddling to track
82             if attributes are dirty; that is, if they're set to some value and then set
83             again, to another value. (The setting can be done by the constructor,
84             builder, default, accessor, etc.)
85              
86             An attribute can be returned to a clean state by invoking its clearer.
87              
88             =for stopwords HashRef's
89              
90             =head1 CAVEAT
91              
92             Note that with one (significant) exceptions we can only track
93             dirtiness at the very first level. That is, if you have an attribute that is
94             a HashRef, we can tell that the _attribute_ is dirty if and only if the
95             actual ref changes, but not if the HashRef's keys/values change. e.g.
96              
97             $self->hashref({ new => 'hash' })
98              
99             would render the 'hashref' attribute dirty, but
100              
101             $self->hashref->{foo} = 'bar'
102              
103             would not.
104              
105             In plainer language: we can only tell if an attribute's value is dirty if our
106             accessors are used to modify its values.
107              
108             The exception to this is...
109              
110             =head1 IMPLICATIONS FOR NATIVE TRAITS
111              
112             We now track when a native trait accessor is used to change the contents of
113             the attribute; this is considered to make the attribute value dirty.
114              
115             This is still new and experimental, so feedback is quite welcome :)
116              
117             =head1 ATTRIBUTE OPTIONS
118              
119             To track a given attribute, the trait must be applied. This package exports a
120             "TrackDirty" function that returns the full (ridiculously long) package name
121             of the trait.
122              
123             Once applied, we have two additional options that can be passed to the
124             attribute constructor (usually via 'has'):
125              
126             =over 4
127              
128             =item is_dirty => method_name
129              
130             is_dirty controls what the name of the "is this attribute's value dirty?"
131             accessor is (returning true on dirty; false otherwise):
132              
133             By default, the accessor is installed as "{attribute_name}_is_dirty";
134              
135             If a legal method name is passed, the accessor is installed under that name;
136              
137             Otherwise we blow up.
138              
139             =item original_value => method_name
140              
141             original_value controls what the name for the original value accessor is
142             installed (returns the original value if dirty, undef otherwise):
143              
144             By default, we do not install an original_value accessor;
145              
146             If a legal method name is passed, the accessor is installed under that name;
147              
148             Otherwise we blow up.
149              
150             =back
151              
152             =head1 SOURCE
153              
154             The development version is on github at L<http://github.com/RsrchBoy/moosex-trackdirty-attributes>
155             and may be cloned from L<git://github.com/RsrchBoy/moosex-trackdirty-attributes.git>
156              
157             =head1 BUGS
158              
159             Please report any bugs or feature requests on the bugtracker website
160             https://github.com/RsrchBoy/moosex-trackdirty-attributes/issues
161              
162             When submitting a bug or request, please include a test-file or a
163             patch to an existing test-file that illustrates the bug or desired
164             feature.
165              
166             =head1 AUTHOR
167              
168             Chris Weyl <cweyl@alumni.drew.edu>
169              
170             =head1 COPYRIGHT AND LICENSE
171              
172             This software is Copyright (c) 2011 by Chris Weyl.
173              
174             This is free software, licensed under:
175              
176             The GNU Lesser General Public License, Version 2.1, February 1999
177              
178             =cut
179              
180              
181             __END__
182