| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | OpenERP::OOM::Roles::Attribute - Meta attribute for implementing dirty attribute tracking | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This code was largely taken from a version of MooseX::TrackDirty before it | ||||||||||||||||||||||||||||
| 8 | was updated to work with Moose 2.0. Then it was cut down to suit our purposes | ||||||||||||||||||||||||||||
| 9 | being uses in the Moose::Exporter. | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | Copyright (C) 2011 OpusVL | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package OpenERP::OOM::Roles::Attribute; | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | has track_dirty => (is => 'rw', isa => 'Bool', default => 1); | |||||||||||||||||||||||||||
| 24 | 3 | has dirty => (is => 'ro', isa => 'Str', predicate => 'has_dirty'); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | has track_attribute_helpers_dirty => | |||||||||||||||||||||||||||
| 27 | (is => 'rw', isa => 'Bool', default => 1); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # wrap our internal clearer | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | after clear_value => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 32 | 0 | my ($self, $instance) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | $instance->_mark_clean($self->name) if $self->track_dirty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3 | }; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | after install_accessors => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.7
| |||||||||||||||||||||||||||||
| 38 | 1 | my ($self, $inline) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | ### in install_accessors, installing if: $self->track_dirty | ||||||||||||||||||||||||||||
| 41 | 1 | ▶ | return unless $self->track_dirty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | my $class = $self->associated_class; | |||||||||||||||||||||||||||
| 44 | 1 | my $name = $self->name; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ### is_dirty: $self->dirty || '' | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $class->add_method($self->dirty, sub { shift->_is_dirty($name) }) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if $self->has_dirty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | $class->add_after_method_modifier( | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $self->clearer => sub { shift->_mark_clean($name) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | ) if $self->has_clearer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # if we're set, we're dirty (cach both writer/accessor) | ||||||||||||||||||||||||||||
| 55 | $class->add_after_method_modifier( | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $self->writer => sub { shift->_mark_dirty($name) } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | ) if $self->has_writer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | $class->add_after_method_modifier( | ||||||||||||||||||||||||||||
| 59 | $self->accessor => | ||||||||||||||||||||||||||||
| 60 | 2 | ▶ | sub { $_[0]->_mark_dirty($name) if exists $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | ) if $self->has_accessor; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | return; | |||||||||||||||||||||||||||
| 64 | 3 | }; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | before _process_options => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 67 | 1 | my ($self, $name, $options) = @_; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | ### before _process_options: $name | ||||||||||||||||||||||||||||
| 70 | $options->{dirty} = $name.'_is_dirty' | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | unless exists $options->{dirty} || !$options->{lazy_build}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $options->{"dirty"} or not $options->{"lazy_build"}
MC/DC0%0/2
exists $options->{"dirty"} or not $options->{"lazy_build"}
exists $options->{"dirty"}
not $options->{"lazy_build"}
Truth table33%1/3
A or not(B)
A= exists $options->{"dirty"}B= not $options->{"lazy_build"}
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 1 | return; | |||||||||||||||||||||||||||
| 74 | 3 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 3 | 1; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||