develooper Front page | perl.moose | Postings from May 2012

Re: MooseX::TrackDirty::Attributes

Thread Previous
From:
Lars Balker
Date:
May 16, 2012 05:20
Subject:
Re: MooseX::TrackDirty::Attributes
Message ID:
CAB-_BaTVWJOVkxWtUuhpH4z9txr9kam0gFbUddpCu+PhatkPCQ@mail.gmail.com
On Wed, May 16, 2012 at 1:11 PM, Brian ROONEY
<brian.xb.rooney@stericsson.com> wrote:
> Is there any way to I can take control of MX::TD::A such that I can decide when to start the dirty tracking?  Specifically, below,  the attributes in Foo::Types::Parameter are populated by reading in a file Foo::Reader->read.  Only after reading in, I then want to trigger the dirty tracking.
>
> Currently the dirty tracking starts after construction of Foo::Types::Parameter which means Foo::Reader::File->param->comment  is immediately dirty  when reading from the file. :(

No it doesn't? But have a look at this:

package Foo::Types::Parameter;
use MooseX::TrackDirty::Attributes;
use Moose;

has 'comment' => (is => "rw", isa => 'Bool', traits => [TrackDirty]);

package main;

my $param = new Foo::Types::Parameter;

$param->comment(1);
$param->comment_is_dirty && warn "1";

$param->comment(0);
$param->comment_is_dirty && warn "2";

$param->meta->get_attribute('comment')->clear_dirty_slot($param);
$param->comment_is_dirty && warn "3";
-- 
Lars Balker                                                  Consult::Perl

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About