Permalink
Browse files

Dirty detection using Attribute class

  • Loading branch information...
1 parent 60db8ae commit 84663e9c6d22fedc5552f2d8cac89bb1ad8795ed @bluescreen10 bluescreen10 committed Nov 2, 2011
Showing with 19 additions and 47 deletions.
  1. +12 −46 lib/Gideon.pm
  2. +7 −1 lib/Gideon/Meta/Attribute/DBI.pm
View
@@ -16,52 +16,18 @@ my $__meta = undef;
my $__store = {};
our %stores = ();
-after 'new' => sub {
-
- my $self = shift;
- my $meta = $self->meta;
-
- for my $attribute (
- map { $meta->get_attribute($_) }
- sort $meta->get_attribute_list
- ) {
-
- my $name = $attribute->name;
-
- $meta->add_before_method_modifier(
- $name,
- sub {
- my $self = shift;
- my $new_value = shift;
- if ( defined $new_value ) {
- my $meta = $self->meta;
- my $attribute = $meta->get_attribute($name);
- my $reader = $attribute->get_read_method;
- my $value = $self->$reader;
- if ( defined $value and $value ne $new_value ) {
- $self->is_modified(1);
- }
- }
- }
- );
- }
- $meta->add_attribute(
- 'is_modified' => (
- is => 'rw',
- isa => 'Bool',
- default => 0,
- )
- );
- $meta->add_attribute(
- 'is_stored' => (
- is => 'rw',
- isa => 'Bool',
- default => 0,
- lazy => 1,
- )
- );
-
-};
+has 'is_modified' => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 0,
+);
+
+has 'is_stored' => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 0,
+ lazy => 1,
+);
sub register_store {
my $class = shift;
@@ -24,7 +24,13 @@ has 'primary_key' => (
predicate => 'has_key',
);
+sub new {
+ my $class = shift;
+ push @_, trigger => sub { $_[0]->is_modified(1) };
+ $class->SUPER::new(@_);
+}
+
package Mouse::Meta::Attribute::Custom::Gideon;
sub register_implementation {'Gideon::Meta::Attribute::DBI'}
-1;
+1;

0 comments on commit 84663e9

Please sign in to comment.