- Timestamp:
- Aug 18, 2013 5:28:12 AM (11 years ago)
- Branches:
- master
- Children:
- 682d2d9
- Parents:
- 19df400
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/github/GitHubBackup.pm
r19df400 r6f31bfb 24 24 25 25 package GitHubBackup; 26 use base qw(Class::Accessor::Fast);27 26 28 27 use strict; … … 30 29 use utf8; 31 30 use Carp qw(croak); 32 33 __PACKAGE__->mk_accessors( qw( 34 directory 35 )); 31 use File::Spec; 36 32 37 33 … … 39 35 sub new { 40 36 my $class = shift; 41 42 37 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; 48 40 } 49 41 … … 70 62 71 63 return $self->{repository}; 64 } 65 66 sub 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}; 72 75 } 73 76 … … 126 129 127 130 package GitHubBackup::Repository; 128 use base qw(Class::Accessor::Fast);129 131 130 132 use strict; … … 134 136 use Git::Repository; 135 137 use File::chdir; 136 138 use File::Spec; 139 use File::Path qw(mkpath); 137 140 138 141 sub new { … … 145 148 } 146 149 147 return $class->SUPER::new($args);150 return bless $args, $class; 148 151 } 149 152 … … 151 154 my $self = shift; 152 155 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; 154 162 } 155 163 … … 157 165 my $self = shift; 158 166 159 my $dir = $self->directory .'/'. $self->{full_name};167 my $dir = $self->directory; 160 168 if (-d "$dir") { 161 169 local $CWD = $dir; … … 166 174 167 175 print "clone ", $dir, "\n"; 176 mkpath $dir; 168 177 Git::Repository->run(clone => '--mirror' => $self->{clone_url} => $dir); 169 178 return $self;
Note: See TracChangeset
for help on using the changeset viewer.