[svk-commit] r2776 - in branches/moose/lib/SVK: Inspector Path
nobody at bestpractical.com
nobody at bestpractical.com
Mon Apr 28 12:50:20 EDT 2008
Author: clkao
Date: Mon Apr 28 12:50:20 2008
New Revision: 2776
Modified:
branches/moose/lib/SVK/Accessor.pm
branches/moose/lib/SVK/Inspector/Root.pm
branches/moose/lib/SVK/Mirror.pm
branches/moose/lib/SVK/Path.pm
branches/moose/lib/SVK/Path/Checkout.pm
branches/moose/lib/SVK/Path/Txn.pm
branches/moose/lib/SVK/Path/View.pm
Log:
moosify SVK::Path and friends.
Modified: branches/moose/lib/SVK/Accessor.pm
==============================================================================
--- branches/moose/lib/SVK/Accessor.pm (original)
+++ branches/moose/lib/SVK/Accessor.pm Mon Apr 28 12:50:20 2008
@@ -49,53 +49,24 @@
#
# END BPS TAGGED BLOCK }}}
package SVK::Accessor;
-use strict;
+use Moose;
-use base qw(Class::Accessor::Fast Class::Data::Inheritable);
-use Storable;
+with qw(MooseX::Clone);
-__PACKAGE__->mk_classdata('_shared_accessors');
-__PACKAGE__->mk_classdata('_clonable_accessors');
+use Storable;
sub mk_shared_accessors {
my $class = shift;
- $class->mk_accessors(@_);
- my $fun = $class->SUPER::can('_shared_accessors');
- no strict 'refs';
- unless (${$class.'::_shared_accessors_init'}) {
- my $y = $fun->($class) || [];
- $class->_shared_accessors(Storable::dclone($y));
- ${$class.'::_shared_accessors_init'} = 1;
- }
-
- push @{$class->_shared_accessors}, @_;
+ # FIXME $class->meta->add_attribute( ... )
+ confess "compat not written yet";
}
sub mk_clonable_accessors {
my $class = shift;
- $class->mk_accessors(@_);
- my $fun = $class->SUPER::can('_clonable_accessors');
- no strict 'refs';
- unless (${$class.'::_clonable_accessors_init'}) {
- my $y = $fun->($class) || [];
- $class->_clonable_accessors(Storable::dclone($y));
- ${$class.'::_clonable_accessors_init'} = 1;
- }
-
- push @{$class->_clonable_accessors}, @_;
+ # FIXME $class->meta->add_attribute( ..., traits => "Clone" )
+ confess "compat not written yet";
}
-sub clonable_accessors {
- my $self = shift;
- return (@{$self->_clonable_accessors});
-}
-
-sub shared_accessors {
- my $self = shift;
- return (@{$self->_shared_accessors});
-}
-
-
sub real_new {
my $self = shift;
$self->SUPER::new(@_);
@@ -108,34 +79,13 @@
return $self->mclone(@arg);
}
-sub clone {
- my ($self) = @_;
-
- my $cloned = ref($self)->real_new;
- for my $key ($self->shared_accessors) {
- $cloned->$key($self->$key);
- }
- for my $key ($self->clonable_accessors) {
- next if $key =~ m/^_/;
- Carp::cluck unless $self->can($key);
- my $value = $self->$key;
- if (UNIVERSAL::can($value, 'clone')) {
- $cloned->$key($value->clone);
- }
- else {
- $cloned->$key(ref $value ? Storable::dclone($value) : $value);
- }
- }
- return $cloned;
-}
-
sub mclone {
my $self = shift;
my $args = ref($_[0]) ? $_[0] : { @_ };
- my $cloned = $self->clone;
+ my $cloned = $self->clone();
for my $key (keys %$args) {
- Carp::cluck unless $cloned->can($key);
- $cloned->$key($args->{$key});
+ Carp::cluck unless $cloned->can($key);
+ $cloned->$key($args->{$key});
}
return $cloned;
}
Modified: branches/moose/lib/SVK/Inspector/Root.pm
==============================================================================
--- branches/moose/lib/SVK/Inspector/Root.pm (original)
+++ branches/moose/lib/SVK/Inspector/Root.pm Mon Apr 28 12:50:20 2008
@@ -123,6 +123,7 @@
sub _anchor_path {
my ($self, $path) = @_;
+ Carp::cluck unless defined $path;
$path = $self->translate($path);
return $path if $path =~ m{^/};
return $self->anchor unless length $path;
Modified: branches/moose/lib/SVK/Mirror.pm
==============================================================================
--- branches/moose/lib/SVK/Mirror.pm (original)
+++ branches/moose/lib/SVK/Mirror.pm Mon Apr 28 12:50:20 2008
@@ -106,7 +106,7 @@
has url => (
- #isa => "Str",
+ #isa => "Str", # can be Maybe[Str], but that's really pointless
is => "rw",
);
Modified: branches/moose/lib/SVK/Path.pm
==============================================================================
--- branches/moose/lib/SVK/Path.pm (original)
+++ branches/moose/lib/SVK/Path.pm Mon Apr 28 12:50:20 2008
@@ -61,24 +61,33 @@
use SVK::Logger;
use SVK::Depot;
use SVK::Root;
-use base 'SVK::Accessor';
+use Moose;
-__PACKAGE__->mk_shared_accessors
- (qw(depot));
+extends qw(SVK::Accessor);
-__PACKAGE__->mk_clonable_accessors
- (qw(revision targets));
-
-__PACKAGE__->mk_accessors
- (qw(_root _inspector _pool));
+has depot => (
+ is => "rw",
+ handles => [qw(depotname repos repospath mirror)],
+);
+
+
+has [qw(revision targets)] => (
+ is => "rw",
+ traits => [qw(Clone)],
+);
+
+has path => (
+ accessor => "path_anchor",
+# traits => [qw(Clone)],
+);
+
+has [qw(_root _inspector _pool)] => (
+ is => "rw",
+ traits => [qw(NoClone)],
+);
use Class::Autouse qw( SVK::Inspector::Root SVK::Target::Universal );
-for my $proxy (qw/depotname repos repospath mirror/) {
- no strict 'refs';
- *{$proxy} = sub { my $self = shift; $self->depot; $self->depot->$proxy(@_) }
-}
-
=head1 NAME
SVK::Path - SVK path class
@@ -780,9 +789,6 @@
return $self->mclone( revision => $revision );
}
-*path_anchor = __PACKAGE__->make_accessor('path');
-push @{__PACKAGE__->_clonable_accessors}, 'path_anchor';
-
sub path_target { $_[0]->{targets}[0] || '' }
use Data::Dumper;
Modified: branches/moose/lib/SVK/Path/Checkout.pm
==============================================================================
--- branches/moose/lib/SVK/Path/Checkout.pm (original)
+++ branches/moose/lib/SVK/Path/Checkout.pm Mon Apr 28 12:50:20 2008
@@ -49,16 +49,29 @@
#
# END BPS TAGGED BLOCK }}}
package SVK::Path::Checkout;
-use strict;
+use Moose;
+
use SVK::Version; our $VERSION = $SVK::VERSION;
-use base 'SVK::Accessor';
+extends 'SVK::Accessor';
use SVK::Path;
-__PACKAGE__->mk_shared_accessors(qw(xd));
-__PACKAGE__->mk_clonable_accessors(qw(report source copath_anchor copath_target));
-__PACKAGE__->mk_accessors(qw(_pool _inspector));
+has xd => ( is => "rw" );
+
+has [qw(report)] => (
+ is => "rw",
+);
+
+has [qw(source copath_anchor copath_target)] => (
+ is => "rw",
+ traits => [qw(Clone)],
+);
+
+has [qw(_pool _inspector)] => (
+ is => "rw",
+ traits => [qw(NoClone)],
+);
use Class::Autouse qw(SVK::Editor::XD SVK::Root::Checkout);
@@ -187,7 +200,7 @@
return $_copath_catsplit->($copath, $paths);
}
-sub report { __PACKAGE__->make_accessor('report')->(@_) }
+#sub report { __PACKAGE__->make_accessor('report')->(@_) }
sub report_copath {
my ($self, $copath) = @_;
Modified: branches/moose/lib/SVK/Path/Txn.pm
==============================================================================
--- branches/moose/lib/SVK/Path/Txn.pm (original)
+++ branches/moose/lib/SVK/Path/Txn.pm Mon Apr 28 12:50:20 2008
@@ -49,9 +49,11 @@
#
# END BPS TAGGED BLOCK }}}
package SVK::Path::Txn;
-use strict;
-use base 'SVK::Path';
-__PACKAGE__->mk_shared_accessors(qw(txn));
+use Moose;
+
+extends 'SVK::Path';
+
+has 'txn' => ( is => "rw" );
sub _get_inspector {
my $self = shift;
Modified: branches/moose/lib/SVK/Path/View.pm
==============================================================================
--- branches/moose/lib/SVK/Path/View.pm (original)
+++ branches/moose/lib/SVK/Path/View.pm Mon Apr 28 12:50:20 2008
@@ -49,14 +49,20 @@
#
# END BPS TAGGED BLOCK }}}
package SVK::Path::View;
-use strict;
+use Moose;
use SVK::Version; our $VERSION = $SVK::VERSION;
use SVK::I18N;
use SVK::Logger;
-use base 'SVK::Path';
+extends 'SVK::Path';
-__PACKAGE__->mk_clonable_accessors(qw(source));
-__PACKAGE__->mk_shared_accessors(qw(view));
+has source => (
+ is => "rw",
+ traits => [qw(Clone)],
+);
+
+has view => (
+ is => "rw",
+);
use SVK::Util qw( abs2rel );
use SVK::Root::View;
More information about the svk-commit
mailing list