Changeset 6f31bfb in lab.git for Dev/github


Ignore:
Timestamp:
Aug 18, 2013 5:28:12 AM (11 years ago)
Author:
Ken-ichi Mito <mitty@…>
Branches:
master
Children:
682d2d9
Parents:
19df400
Message:

remove Class::Accessor::Fast

  • handle directory path correctly
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/github/GitHubBackup.pm

    r19df400 r6f31bfb  
    2424 
    2525package GitHubBackup; 
    26 use base qw(Class::Accessor::Fast); 
    2726 
    2827use strict; 
     
    3029use utf8; 
    3130use Carp qw(croak); 
    32  
    33 __PACKAGE__->mk_accessors( qw( 
    34     directory 
    35 )); 
     31use File::Spec; 
    3632 
    3733 
     
    3935sub new { 
    4036    my $class = shift; 
    41      
    4237    my $args = (ref $_[0] eq 'HASH') ? $_[0] : {@_}; 
    43     if (! $args->{directory}) { 
    44         $args->{directory} = "."; 
    45     } 
    46      
    47     return $class->SUPER::new($args); 
     38     
     39    return bless $args, $class; 
    4840} 
    4941 
     
    7062     
    7163    return $self->{repository}; 
     64} 
     65 
     66sub directory { 
     67    my $self = shift; 
     68    my $args = shift; 
     69     
     70    if (defined $args) { 
     71        $self->{directory} = File::Spec->rel2abs($args); 
     72    } 
     73     
     74    return $self->{directory}; 
    7275} 
    7376 
     
    126129 
    127130package GitHubBackup::Repository; 
    128 use base qw(Class::Accessor::Fast); 
    129131 
    130132use strict; 
     
    134136use Git::Repository; 
    135137use File::chdir; 
    136  
     138use File::Spec; 
     139use File::Path qw(mkpath); 
    137140 
    138141sub new { 
     
    145148    } 
    146149     
    147     return $class->SUPER::new($args); 
     150    return bless $args, $class; 
    148151} 
    149152 
     
    151154    my $self = shift; 
    152155     
    153     return $self->{directory}->(); 
     156    my $path = $self->{full_name}; 
     157    if (my $base = $self->{directory}->()) { 
     158        $path = File::Spec->catfile($base, $path); 
     159    } 
     160     
     161    return $path; 
    154162} 
    155163 
     
    157165    my $self = shift; 
    158166     
    159     my $dir = $self->directory .'/'. $self->{full_name}; 
     167    my $dir = $self->directory; 
    160168    if (-d "$dir") { 
    161169        local $CWD = $dir; 
     
    166174     
    167175    print "clone ", $dir, "\n"; 
     176    mkpath $dir; 
    168177    Git::Repository->run(clone => '--mirror' => $self->{clone_url} => $dir); 
    169178    return $self; 
Note: See TracChangeset for help on using the changeset viewer.