| 1 | package RackMan::SCM; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 2 | ▶ | use Cwd; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 2 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | |||||||||||||||
| 9 | 2 | enum ScmType => [qw< none cvs svn bzr hg git >]; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 2 | has type => ( | |||||||||||||
| 12 | is => "ro", | ||||||||||||||
| 13 | isa => "ScmType", | ||||||||||||||
| 14 | required => 1, | ||||||||||||||
| 15 | ); | ||||||||||||||
| 16 | |||||||||||||||
| 17 | 2 | has path => ( | |||||||||||||
| 18 | is => "rw", | ||||||||||||||
| 19 | isa => "Str", | ||||||||||||||
| 20 | ); | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 2 | has prefix => ( | |||||||||||||
| 23 | is => "rw", | ||||||||||||||
| 24 | isa => "Str", | ||||||||||||||
| 25 | ); | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 2 | has verbose => ( | |||||||||||||
| 28 | is => "rw", | ||||||||||||||
| 29 | isa => "Bool", | ||||||||||||||
| 30 | ); | ||||||||||||||
| 31 | |||||||||||||||
| 32 | |||||||||||||||
| 33 | 2 | my %xlate = ( | |||||||||||||
| 34 | bzr => { | ||||||||||||||
| 35 | update => [ ["update"] ], | ||||||||||||||
| 36 | commit => [ ["commit", "%0%", "-m", "%1%"], ["push"] ], | ||||||||||||||
| 37 | }, | ||||||||||||||
| 38 | git => { | ||||||||||||||
| 39 | update => [ ["pull"] ], | ||||||||||||||
| 40 | commit => [ ["commit", "%0%", "-m", "%1%"], ["push"] ], | ||||||||||||||
| 41 | }, | ||||||||||||||
| 42 | hg => { | ||||||||||||||
| 43 | update => [ ["pull"], ["update"] ], | ||||||||||||||
| 44 | commit => [ ["commit", "%0%", "-m", "%1%"], ["push"] ], | ||||||||||||||
| 45 | }, | ||||||||||||||
| 46 | ); | ||||||||||||||
| 47 | |||||||||||||||
| 48 | |||||||||||||||
| 49 | # | ||||||||||||||
| 50 | # _exec() | ||||||||||||||
| 51 | # ----- | ||||||||||||||
| 52 | 3 | ▶ | sub _exec { | ||||||||||||
|
Subroutine
_exec: called CC=5 SCAR=18.1
| |||||||||||||||
| 53 | 3 | my ($self, @batch) = @_; | |||||||||||||
| 54 | |||||||||||||||
| 55 | 3 | my $curdir = getcwd(); | |||||||||||||
| 56 | 3 | ▶ | chdir $self->path if $self->path; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | |||||||||||||||
| 58 | 3 | for my $cmd (@batch) { | |||||||||||||
| 59 | 0 | ▶ | print $self->prefix, join " ", map { / / ? "'$_'" : $_ } @$cmd, "\n" | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 60 | if $self->verbose; | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 4 | system @$cmd; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 3 | chdir $curdir; | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | |||||||||||||||
| 69 | # | ||||||||||||||
| 70 | # add() | ||||||||||||||
| 71 | # --- | ||||||||||||||
| 72 | 2 | ▶ | sub add { | ||||||||||||
|
Subroutine
add: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 73 | 2 | my ($self, @args) = @_; | |||||||||||||
| 74 | |||||||||||||||
| 75 | 2 | my $prog = $self->type; | |||||||||||||
| 76 | 2 | ▶ | return if $prog eq "none"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 77 | 1 | my @batch = ( [$prog, "add", $args[0]] ); | |||||||||||||
| 78 | |||||||||||||||
| 79 | 1 | $self->_exec(@batch); | |||||||||||||
| 80 | } | ||||||||||||||
| 81 | |||||||||||||||
| 82 | |||||||||||||||
| 83 | # | ||||||||||||||
| 84 | # commit() | ||||||||||||||
| 85 | # ------ | ||||||||||||||
| 86 | 2 | ▶ | sub commit { | ||||||||||||
|
Subroutine
commit: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 87 | 2 | my ($self, @args) = @_; | |||||||||||||
| 88 | |||||||||||||||
| 89 | 2 | my $prog = $self->type; | |||||||||||||
| 90 | 2 | ▶ | return if $prog eq "none"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 1 | my @batch; | |||||||||||||
| 92 | |||||||||||||||
| 93 | 1 | ▶ | if (ref $xlate{$prog}{commit}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 1 | for my $cmd (@{ $xlate{$prog}{commit} }) { | |||||||||||||
| 95 | 2 | push @batch, [ $prog, map { s/%(\d)%/$args[$1]/; $_ } @$cmd ]; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | } | ||||||||||||||
| 98 | else { | ||||||||||||||
| 99 | 0 | push @batch, [ $prog, "commit", $args[0], "-m", $args[1] ]; | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 1 | $self->_exec(@batch); | |||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | |||||||||||||||
| 106 | # | ||||||||||||||
| 107 | # update() | ||||||||||||||
| 108 | # ------ | ||||||||||||||
| 109 | 2 | ▶ | sub update { | ||||||||||||
|
Subroutine
update: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||
| 110 | 2 | my ($self, @args) = @_; | |||||||||||||
| 111 | |||||||||||||||
| 112 | 2 | my $prog = $self->type; | |||||||||||||
| 113 | 2 | ▶ | return if $prog eq "none"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 114 | 1 | my @batch; | |||||||||||||
| 115 | |||||||||||||||
| 116 | 1 | ▶ | if (ref $xlate{$prog}{update}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 117 | 1 | for my $cmd (@{ $xlate{$prog}{update} }) { | |||||||||||||
| 118 | 1 | push @batch, [ $prog, map { s/%(\d)%/$args[$1]/; $_ } @$cmd ]; | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | else { | ||||||||||||||
| 122 | 0 | ▶ | $args[0] ||= "."; | ||||||||||||
|
Condition0%0/2
$args[0] ||= "."
MC/DC0%0/1
$args[0] ||= "."
$args[0]
Truth table0%0/2
A
A= $args[0]
| |||||||||||||||
| 123 | 0 | push @batch, [ $prog, "update", $args[0] ]; | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 1 | $self->_exec(@batch); | |||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | |||||||||||||||
| 130 | 2 | __PACKAGE__->meta->make_immutable | |||||||||||||
| 131 | |||||||||||||||
| 132 | __END__ | ||||||||||||||