| 1 | package App::Rgit::Command; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use App::Rgit::Utils qw/:codes/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | App::Rgit::Command - Base class for App::Rgit commands. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | Version 0.08 | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Base class for L<App::Rgit> commands. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | This is an internal class to L<rgit>. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | =head2 C<< new cmd => $cmd, args => \@args >> | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | Creates a new command object for C<$cmd> that is bound to be called with arguments C<@args>. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | my %commands; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | __PACKAGE__->action($_ => 'Once') for qw/daemon gui help init version/, ' '; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 20 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 20 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 20 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 20 | my $cmd = $args{cmd}; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 20 | ▶ | $cmd = ' ' unless defined $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 20 | my $action = $class->action($cmd); | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | ▶ | if ($class eq __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 18 | $class = $action; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | Carp::confess("Command $cmd should be executed as a $action") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | unless $class->isa($action); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 19 | ▶ | eval "require $action; 1" or Carp::confess("Couldn't load $action: $@"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | bless { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | cmd => $cmd, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | args => $args{args} || [ ], | ||||||||||||||||||||||||||||||||||||||||||
| 62 | policy => $args{policy}, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 18 | ▶ | }, $class; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'args'} || []
MC/DC100%1/1
$args{'args'} || []
$args{'args'}
Truth table100%2/2
A
A= $args{'args'}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =head2 C<< action $cmd [ => $pkg ] >> | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | If C<$pkg> is supplied, handles command C<$cmd> with C<$pkg> objects. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | Otherwise, returns the current class for C<$cmd>. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 57 | ▶ | sub action { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
action: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 57 | my ($self, $cmd, $pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 57 | ▶ | if (not defined $cmd) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | return unless defined $self and ref $self and $self->isa(__PACKAGE__); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $self and ref $self and $self->isa(__PACKAGE__)
defined $self and ref $self
MC/DC100%3/3
defined $self and ref $self and $self->isa(__PACKAGE__)
defined $self
ref $self
$self->isa(__PACKAGE__)
Truth table100%4/4
A and B and C
A= defined $selfB= ref $selfC= $self->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $cmd = $self->cmd; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 54 | ▶ | unless (defined $pkg) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 23 | ▶ | return __PACKAGE__ . '::Each' unless defined $commands{$cmd}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | return $commands{$cmd} | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 31 | ▶ | $pkg = __PACKAGE__ . '::' . $pkg unless $pkg =~ /:/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 31 | $commands{$cmd} = $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =head2 C<report $conf, $repo, $status> | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | Reports that the execution of the command in C<$repo> exited with C<$status> to the current command's policy. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | Returns what policy C<report> method returned, which should be one of the policy codes listed in C<App::Rgit::Utils>. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | sub report { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
report: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 11 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | my $code = $self->policy->handle(@_); | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 11 | ▶ | return defined $code ? $code : NEXT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head2 C<cmd> | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =head2 C<args> | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head2 C<policy> | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | Read-only accessors. | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 5 | ▶ | eval "sub $_ { \$_[0]->{$_} }" for qw/cmd args policy/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Subroutine
cmd: called CC=1 SCAR=0.0
Subroutine
policy: called CC=1 SCAR=0.0
Pod
documented
Pod
documented
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | =head2 C<run $conf> | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | Runs the command with a L<App::Rgit::Config> configuration object. | ||||||||||||||||||||||||||||||||||||||||||
| 119 | Handles back the code to return to the system and the last policy. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | Implemented in subclasses. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | L<rgit>. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | Vincent Pit, C<< <perl at profvince.com> >>, L<http://profvince.com>. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | You can contact me by mail or on C<irc.perl.org> (vincent). | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | Please report any bugs or feature requests to C<bug-rgit at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=rgit>. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | perldoc App::Rgit::Command | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | Copyright 2008,2009,2010 Vincent Pit, all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | 1; # End of App::Rgit::Command | |||||||||||||||||||||||||||||||||||||||||