[svk-commit] r2772 - in branches/moose/lib/SVK: Mirror/Backend

nobody at bestpractical.com nobody at bestpractical.com
Mon Apr 28 11:15:27 EDT 2008


Author: clkao
Date: Mon Apr 28 11:15:25 2008
New Revision: 2772

Modified:
   branches/moose/lib/SVK/Mirror.pm
   branches/moose/lib/SVK/Mirror/Backend/SVNRa.pm

Log:
uri sanity.

Modified: branches/moose/lib/SVK/Mirror.pm
==============================================================================
--- branches/moose/lib/SVK/Mirror.pm	(original)
+++ branches/moose/lib/SVK/Mirror.pm	Mon Apr 28 11:15:25 2008
@@ -50,6 +50,7 @@
 # END BPS TAGGED BLOCK }}}
 package SVK::Mirror;
 use Moose;
+use Moose::Util::TypeConstraints;
 
 use SVN::Core;
 use SVK::Logger;
@@ -103,43 +104,54 @@
 
 =cut
 
+
+# for SVK::Moose::Types
+class_type "URI";
+use URI ();
+subtype "SVK::URL" => ( as "URI" );
+
+coerce "SVK::URL" => (
+    from "Str",
+    via {
+        my $uri = shift;
+        $uri =~ s{/$}{};
+        URI->new( uri_unescape($uri) );
+    },
+);
+
+has _url => (
+    isa => "SVK::URL",
+    is  => "rw",
+    coerce => 1,
+    init_arg => "url",
+    handles => { stringify => "url" },
+);
+
 sub create {
     my ( $class, $args ) = @_;
-    my $self = $class->SUPER::new($args);
 
-    # in has uri, use a builder to handle this or do it in submethod BUILD
-    $self->{url} =~ s{/+$}{}g;
-    $self->{url} = uri_unescape($self->{url});
+    my $self = $class->new($args);
 
     if ( $self->path eq '/' ) {
-        # has backend => ( lazy_build => 1 )
-        # sub _build_backend {
-        $self->_backend(
-            $self->_create_backend( 'SVNSync',
-                $args->{backend_options} )
+        $self->_backend($self->_create_backend( 'SVNSync', $args->{backend_options} ));
+    } else {
+        my $t = $self->get_svkpath('/');
+
+        my ($editor, %opt) = $t->get_dynamic_editor(
+            ignore_mirror => 1,
+            message       => loc('Mirror initialized for %1', $self->url),
+            author        => $ENV{USER},
         );
-        #}
-        return $self;
-    }
-
-    my $t = $self->get_svkpath('/');
-
-    my ($editor, %opt) = $t->get_dynamic_editor(
-        ignore_mirror => 1,
-        message       => loc('Mirror initialized for %1', $self->url),
-        author        => $ENV{USER},
-    );
-
-    $self->_backend(
-        $self->_create_backend( $args->{backend}, $args->{backend_options}, $opt{txn}, $editor )
-    );
+    
+        $self->_backend( $self->_create_backend( $args->{backend}, $args->{backend_options}, $opt{txn}, $editor ) );
 
-    my %mirrors = map { ( $_ => 1 ) } $self->path,
-        split( /\n/, $t->root->node_prop( '/', 'svm:mirror' ) || '' );
+        my %mirrors = map { ( $_ => 1 ) } $self->path,
+            split( /\n/, $t->root->node_prop( '/', 'svm:mirror' ) || '' );
 
-    $editor->change_dir_prop( $editor->_root_baton, 'svm:mirror',
-        join( "\n", ( grep length, sort keys %mirrors ), '' ) );
-    $editor->close_edit;
+        $editor->change_dir_prop( $editor->_root_baton, 'svm:mirror',
+            join( "\n", ( grep length, sort keys %mirrors ), '' ) );
+        $editor->close_edit;
+    }
 
     return $self;
 }
@@ -162,7 +174,7 @@
 
 sub load {
     my ( $class, $args ) = @_;
-    my $self = $class->SUPER::new($args);
+    my $self = $class->new($args);
 
     my $backend = $self->path eq '/' ? 'SVNSync' : 'SVNRa';
     $self->_backend(

Modified: branches/moose/lib/SVK/Mirror/Backend/SVNRa.pm
==============================================================================
--- branches/moose/lib/SVK/Mirror/Backend/SVNRa.pm	(original)
+++ branches/moose/lib/SVK/Mirror/Backend/SVNRa.pm	Mon Apr 28 11:15:25 2008
@@ -49,8 +49,7 @@
 # 
 # END BPS TAGGED BLOCK }}}
 package SVK::Mirror::Backend::SVNRa;
-use strict;
-use warnings;
+use Moose;
 
 use SVN::Core;
 use SVN::Ra;
@@ -62,7 +61,6 @@
 use SVK::Logger;
 use SVK::Editor::FilterProp;
 use SVK::Editor::Composite;
-use Moose;
 
 use Class::Autouse qw(SVK::Editor::SubTree SVK::Editor::CopyHandler SVK::Editor::Translate);
 
@@ -71,12 +69,13 @@
 ## has ($.source_root, $.source_path, $.fromrev)
 
 # We'll extract SVK::Mirror::Backend later.
-# use base 'SVK::Mirror::Backend';
-use base 'Class::Accessor::Fast';
+# extends 'SVK::Mirror::Backend';
 
 # for this: things without _'s will probably move to base
 # SVK::Mirror::Backend
-__PACKAGE__->mk_accessors(qw(_config _auth_baton _auth_ref _auth_baton source_root source_path fromrev _has_replay _cached_ra use_pipeline));
+has [qw(_config _auth_baton _auth_ref _auth_baton source_root source_path fromrev _has_replay _cached_ra use_pipeline)] => (
+    is => "rw",
+);
 
 has mirror => (
     is => "rw",
@@ -101,7 +100,7 @@
 sub new {
     my ( $class, $args ) = @_;
     unless ( defined $args->{use_pipeline} ) {
-        $args->{use_pipeline} = 0;#IS_WIN32 ? 0 : 1;
+        $args->{use_pipeline} = 0;#IS_WIN32 ? 0 : 1; # default => ...
     }
     return $class->SUPER::new($args);
 }


More information about the svk-commit mailing list