| 1 | use 5.008; # utf8 | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use utf8; | ||
| 5 | |||
| 6 | package Git::Wrapper::Plus::Ref::Branch; | ||
| 7 | $Git::Wrapper::Plus::Ref::Branch::VERSION = '0.004010'; | ||
| 8 | # ABSTRACT: A Branch object | ||
| 9 | |||
| 10 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | ||
| 11 | |||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | |||
| 38 | |||
| 39 | use Moo qw( extends ); | ||
| 40 | extends 'Git::Wrapper::Plus::Ref'; | ||
| 41 | |||
| 42 | our @CARP_NOT; | ||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | ## no critic (ProhibitMixedCaseSubs) | ||
| 53 | sub new_from_Ref { | ||
| 54 | my ( $class, $source_object ) = @_; | ||
| 55 | if ( not $source_object->can('name') ) { | ||
| 56 | require Carp; | ||
| 57 | return Carp::croak("Object $source_object does not respond to ->name, cannot Ref -> Branch"); | ||
| 58 | } | ||
| 59 | my $name = $source_object->name; | ||
| 60 | ## no critic ( Compatibility::PerlMinimumVersionAndWhy ) | ||
| 61 | if ( $name =~ qr{\Arefs/heads/(.+\z)}msx ) { | ||
| 62 | return $class->new( | ||
| 63 | git => $source_object->git, | ||
| 64 | name => $1, | ||
| 65 | ); | ||
| 66 | } | ||
| 67 | require Carp; | ||
| 68 | Carp::croak("Path $name is not in refs/heads/*, cannot convert to Branch object"); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | sub refname { | ||
| 78 | my ($self) = @_; | ||
| 79 | return 'refs/heads/' . $self->name; | ||
| 80 | } | ||
| 81 | |||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | |||
| 98 | ## no critic (ProhibitBuiltinHomonyms) | ||
| 99 | |||
| 100 | sub delete { | ||
| 101 | my ( $self, $params ) = @_; | ||
| 102 | if ( $params->{force} ) { | ||
| 103 | return $self->git->branch( '-D', $self->name ); | ||
| 104 | } | ||
| 105 | return $self->git->branch( '-d', $self->name ); | ||
| 106 | |||
| 107 | } | ||
| 108 | |||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | sub move { | ||
| 120 | my ( $self, $new_name, $params ) = @_; | ||
| 121 | if ( not defined $new_name or not length $new_name ) { | ||
| 122 | require Carp; | ||
| 123 | ## no critic (ProhibitLocalVars) | ||
| 124 | local @CARP_NOT = __PACKAGE__; | ||
| 125 | Carp::croak(q[Move requires a defined argument to move to, with length >= 1 ]); | ||
| 126 | } | ||
| 127 | if ( $params->{force} ) { | ||
| 128 | return $self->git->branch( '-M', $self->name, $new_name ); | ||
| 129 | } | ||
| 130 | return $self->git->branch( '-m', $self->name, $new_name ); | ||
| 131 | } | ||
| 132 | |||
| 133 | no Moo; | ||
| 134 | 1; | ||
| 135 | |||
| 136 | __END__ |