File Coverage

File:blib/lib/Git/ReleaseRepo/Command.pm
Coverage:91.8%

linestmtbrancondsubpodtimecode
1package Git::ReleaseRepo::Command;
2
3
2
2
2
2185
2
31
use strict;
4
2
2
2
4
2
22
use warnings;
5
2
2
2
3010
656483
6
use Moose;
6
2
2
2
7919
2
10
use App::Cmd::Setup -command;
7
2
2
2
217
2
54
use Cwd qw( getcwd );
8
2
2
2
4
2
49
use YAML qw( LoadFile DumpFile );
9
2
2
2
4
2
41
use List::Util qw( first );
10
2
2
2
3009
14879
64
use File::HomeDir;
11
2
2
2
6
0
55
use File::Spec::Functions qw( catfile catdir );
12
2
2
2
6
1
9
use Git::Repository qw( +Git::ReleaseRepo::Repository );
13
14has config_file => (
15    is => 'ro',
16    isa => 'Str',
17    lazy => 1,
18    default => sub {
19        catfile( $_[0]->repo_dir, '.git', 'release' );
20    },
21);
22
23has config => (
24    is => 'ro',
25    isa => 'HashRef',
26    lazy => 1,
27    default => sub {
28        my ( $self ) = @_;
29        if ( -f $self->config_file ) {
30            return LoadFile( $self->config_file ) || {};
31        }
32        else {
33            return {};
34        }
35    },
36);
37
38sub write_config {
39
0
0
0
    my ( $self ) = @_;
40
0
0
    return DumpFile( $self->config_file, $self->config );
41}
42
43has repo_dir => (
44    is => 'rw',
45    isa => 'Str',
46    lazy => 1,
47    default => sub { getcwd },
48);
49
50has git => (
51    is => 'ro',
52    isa => 'Git::Repository',
53    lazy => 1,
54    default => sub {
55        my $repo_dir = $_[0]->repo_dir;
56        my $git = Git::Repository->new(
57            work_tree => $_[0]->repo_dir,
58            git_dir => catdir( $_[0]->repo_dir, '.git' ),
59        );
60        return $git;
61    },
62);
63
64has release_prefix => (
65    is => 'rw',
66    isa => 'Str',
67    lazy => 1,
68    default => sub {
69        return $_[0]->config->{version_prefix};
70    },
71);
72
73sub repo_name_from_url {
74
4
0
10
    my ( $self, $repo_url ) = @_;
75
4
43
    my ( $repo_name ) = $repo_url =~ m{/([^/]+)$};
76
4
8
    $repo_name =~ s/[.]git$//;
77
4
19
    return $repo_name;
78}
79
80sub opt_spec {
81
45
1
227
    return ();
82}
83
84sub execute {
85
44
1
25746
    my ( $self, $opt, $args ) = @_;
86
87
44
146
    inner();
88}
89
90
2
2
2
572
2
5
no Moose;
91__PACKAGE__->meta->make_immutable;
921;