| 1 | # PANT::Svn - Provide support for Svn operations | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package PANT::Svn; | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 1 | ▶ | use 5.008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 1 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 1 | ▶ | use Cwd; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use XML::Writer; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Exporter; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 1 | our @ISA = qw(Exporter); | |||||||||||||
| 14 | |||||||||||||||
| 15 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||
| 16 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||
| 17 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||
| 18 | |||||||||||||||
| 19 | # This allows declaration use PANT ':all'; | ||||||||||||||
| 20 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||
| 21 | # will save memory. | ||||||||||||||
| 22 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw() ] ); | |||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||
| 25 | |||||||||||||||
| 26 | 1 | our @EXPORT = qw( ); | |||||||||||||
| 27 | |||||||||||||||
| 28 | 1 | our $VERSION = '0.02'; | |||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | 1 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 32 | 1 | my($clsname, $writer, @rest) =@_; | |||||||||||||
| 33 | 1 | my $self = { | |||||||||||||
| 34 | writer=>$writer, | ||||||||||||||
| 35 | @rest, | ||||||||||||||
| 36 | }; | ||||||||||||||
| 37 | 1 | bless $self, $clsname; | |||||||||||||
| 38 | 1 | return $self; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 3 | ▶ | sub Run { | ||||||||||||
|
Subroutine
Run: called CC=9 SCAR=24.8
Pod
documented
| |||||||||||||||
| 42 | 3 | my($self, $cmd, %args) = @_; | |||||||||||||
| 43 | 3 | my $writer = $self->{writer}; | |||||||||||||
| 44 | 3 | my $cdir = "."; | |||||||||||||
| 45 | 3 | ▶ | if ($args{directory}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | $cdir = getcwd; | |||||||||||||
| 47 | 0 | ▶ | chdir($args{directory}) || Abort("Can't change to directory $args{directory}"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | } | ||||||||||||||
| 50 | 3 | $writer->startTag('li'); | |||||||||||||
| 51 | 3 | $writer->characters("Run $cmd\n"); | |||||||||||||
| 52 | 3 | my $output; | |||||||||||||
| 53 | my $retval; | ||||||||||||||
| 54 | 3 | ▶ | if ($self->{dryrun}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 0 | $output = "Output of the command $cmd would be here"; | |||||||||||||
| 56 | 0 | $retval = 1; | |||||||||||||
| 57 | } | ||||||||||||||
| 58 | else { | ||||||||||||||
| 59 | 3 | $writer->startTag('pre'); | |||||||||||||
| 60 | 3 | $cmd .= " 2>&1"; # collect stderr too | |||||||||||||
| 61 | 3 | $self->{lines} = []; | |||||||||||||
| 62 | 3 | ▶ | if (open(PIPE, "$cmd |")) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 3 | ▶ | while(my $line = <PIPE>) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 10 | $writer->characters($line); | |||||||||||||
| 65 | 10 | push(@ {$self->{lines} }, $line); | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | 3 | close(PIPE); | |||||||||||||
| 68 | 3 | $retval = $? == 0; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | else { | ||||||||||||||
| 71 | 0 | $retval = 0; | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | 3 | $writer->endTag('pre'); | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | 3 | ▶ | $writer->characters("$cmd failed: $!") if ($retval == 0); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 3 | $writer->endTag('li'); | |||||||||||||
| 77 | 0 | ▶ | do { chdir($cdir) || Abort("Can't change back to $cdir: $!"); } if ($args{directory}); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 78 | 3 | return $retval; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 3 | ▶ | sub HasUpdate { | ||||||||||||
|
Subroutine
HasUpdate: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||
| 82 | 3 | my $self = shift; | |||||||||||||
| 83 | 3 | foreach my $line (@{ $self->{lines} }) { | |||||||||||||
| 84 | #A Added | ||||||||||||||
| 85 | #D Deleted | ||||||||||||||
| 86 | #U Updated | ||||||||||||||
| 87 | #C Conflict | ||||||||||||||
| 88 | #G Merged | ||||||||||||||
| 89 | #Restored | ||||||||||||||
| 90 | 3 | ▶ | next if ($line =~ /^At /); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | # treat these two as updates | ||||||||||||||
| 92 | 3 | ▶ | return 1 if ($line =~ /^Updated to /); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | 3 | ▶ | return 1 if ($line =~ /^Restored /); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | 3 | ▶ | if ($line =~ /^[ADUM][A-Z]?\s+/) { # Its a change, one out, all out. | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 95 | 2 | return 1; | |||||||||||||
| 96 | } | ||||||||||||||
| 97 | } | ||||||||||||||
| 98 | 1 | return 0; | |||||||||||||
| 99 | } | ||||||||||||||
| 100 | |||||||||||||||
| 101 | 0 | ▶ | sub HasLocalMod { | ||||||||||||
|
Subroutine
HasLocalMod: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||
| 103 | 0 | foreach my $line (@{ $self->{lines} }) { | |||||||||||||
| 104 | # not sure what to look for. | ||||||||||||||
| 105 | } | ||||||||||||||
| 106 | 0 | return 0; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | 3 | ▶ | sub HasConflict { | ||||||||||||
|
Subroutine
HasConflict: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 109 | 3 | my $self = shift; | |||||||||||||
| 110 | 3 | foreach my $line (@{ $self->{lines} }) { | |||||||||||||
| 111 | 10 | ▶ | if ($line =~ /^[C][A-Z]?\s+/) { # Its a conflict | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 112 | 1 | return 1; | |||||||||||||
| 113 | } | ||||||||||||||
| 114 | } | ||||||||||||||
| 115 | 2 | return 0; | |||||||||||||
| 116 | } | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 1 | 1; | |||||||||||||
| 119 | __END__ | ||||||||||||||