[Bps-public-commit] r12458 - in Prophet/branches/moose: .
sartak at bestpractical.com
sartak at bestpractical.com
Sat May 17 05:48:41 EDT 2008
Author: sartak
Date: Sat May 17 05:48:41 2008
New Revision: 12458
Modified:
Prophet/branches/moose/ (props changed)
Prophet/branches/moose/lib/Prophet/Change.pm
Prophet/branches/moose/lib/Prophet/Conflict.pm
Log:
r56168 at onn: sartak | 2008-05-17 05:48:35 -0400
Moosify Prophet::Change
Modified: Prophet/branches/moose/lib/Prophet/Change.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/Change.pm (original)
+++ Prophet/branches/moose/lib/Prophet/Change.pm Sat May 17 05:48:41 2008
@@ -1,12 +1,46 @@
-use warnings;
-use strict;
-
package Prophet::Change;
-use base qw/Class::Accessor/;
-
+use Moose;
+use Moose::Util::TypeConstraints;
+use MooseX::AttributeHelpers;
use Prophet::PropChange;
use Params::Validate;
-__PACKAGE__->mk_accessors(qw/record_type record_uuid change_type resolution_cas/);
+
+has record_type => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has record_uuid => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has change_type => (
+ is => 'rw',
+ isa => enum([qw/add_file add_dir update_file delete/]),
+);
+
+has resolution_cas => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has is_resolution => (
+ is => 'rw',
+ isa => 'Bool',
+);
+
+has prop_changes => (
+ metaclass => 'Collection::Array',
+ is => 'rw',
+ isa => 'ArrayRef[Prophet::PropChange]',
+ auto_deref => 1,
+ default => sub { [] },
+ provides => {
+ empty => 'has_prop_changes',
+ push => '_add_prop_change',
+ },
+);
=head1 NAME
@@ -28,8 +62,7 @@
=head2 change_type
-One of create_file, add_dir, update_file, delete
-XXX TODO is it create_file or add_file?
+One of add_file, add_dir, update_file, delete
=head2 prop_changes [\@PROPCHANGES]
@@ -37,12 +70,6 @@
=cut
-sub prop_changes {
- my $self = shift;
- $self->{prop_changes} = shift if @_;
- return @{ $self->{prop_changes} || [] };
-}
-
=head2 new_from_conflict( $conflict )
=cut
@@ -71,13 +98,12 @@
sub add_prop_change {
my $self = shift;
my %args = validate( @_, { name => 1, old => 0, new => 0 } );
- my $change = Prophet::PropChange->new();
- $change->name( $args{'name'} );
- $change->old_value( $args{'old'} );
- $change->new_value( $args{'new'} );
-
- push @{ $self->{prop_changes} }, $change;
-
+ my $change = Prophet::PropChange->new(
+ name => $args{'name'},
+ old_value => $args{'old'},
+ new_value => $args{'new'},
+ );
+ $self->_add_prop_change($change);
}
sub as_hash {
@@ -111,4 +137,8 @@
return $self;
}
+__PACKAGE__->meta->make_immutable;
+no Moose;
+no Moose::Util::TypeConstraints;
+
1;
Modified: Prophet/branches/moose/lib/Prophet/Conflict.pm
==============================================================================
--- Prophet/branches/moose/lib/Prophet/Conflict.pm (original)
+++ Prophet/branches/moose/lib/Prophet/Conflict.pm Sat May 17 05:48:41 2008
@@ -49,7 +49,7 @@
for my $conflicting_change ( @{ $self->conflicting_changes } ) {
for (@resolvers) {
if ( my $resolution = $_->( $conflicting_change, $self, $resdb ) ) {
- $resolutions->add_change( change => $resolution ) if $resolution->prop_changes;
+ $resolutions->add_change( change => $resolution ) if $resolution->has_prop_changes;
last;
}
}
More information about the Bps-public-commit
mailing list