| 1 | # | ||||||||||
| 2 | # This file is part of Dist-Zilla-Stash-Store-Git | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is Copyright (c) 2014 by Chris Weyl. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software, licensed under: | ||||||||||
| 7 | # | ||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||
| 9 | # | ||||||||||
| 10 | package Dist::Zilla::Stash::Store::Git; | ||||||||||
| 11 | 4 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 4 | $Dist::Zilla::Stash::Store::Git::AUTHORITY = 'cpan:RSRCHBOY'; | |||||||||
| 13 | } | ||||||||||
| 14 | # git description: 0.000004-1-g398e665 | ||||||||||
| 15 | 4 | $Dist::Zilla::Stash::Store::Git::VERSION = '0.000005'; | |||||||||
| 16 | |||||||||||
| 17 | # ABSTRACT: A common place to store and interface with git | ||||||||||
| 18 | |||||||||||
| 19 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 4 | ▶ | use MooseX::AttributeShortcuts; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 4 | ▶ | use MooseX::RelatedClasses; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 4 | ▶ | use autobox::Core; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 4 | ▶ | use version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 4 | ▶ | use Git::Wrapper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 4 | ▶ | use Version::Next; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 4 | ▶ | use Hash::Merge::Simple 'merge'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 4 | with 'Dist::Zilla::Role::Store'; | |||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | around stash_from_config => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | my ($orig, $class) = (shift, shift); | |||||||||
| 36 | 0 | my ($name, $args, $section) = @_; | |||||||||
| 37 | |||||||||||
| 38 | 0 | $args = { _zilla => delete $args->{_zilla}, store_config => $args }; | |||||||||
| 39 | 0 | return $class->$orig($name, $args, $section); | |||||||||
| 40 | 4 | }; | |||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub default_config { | ||||||||
|
Subroutine
default_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 44 | 0 | my $self = shift @_; | |||||||||
| 45 | |||||||||||
| 46 | return { | ||||||||||
| 47 | 0 | 'version.regexp' => '^v(.+)$', | |||||||||
| 48 | 'version.first' => '0.001', | ||||||||||
| 49 | 'version.next' => $self->_default_next_version, | ||||||||||
| 50 | }; | ||||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | |||||||||||
| 54 | has dynamic_config => ( | ||||||||||
| 55 | traits => [ 'Hash' ], | ||||||||||
| 56 | is => 'lazy', | ||||||||||
| 57 | isa => 'HashRef', | ||||||||||
| 58 | 0 | ▶ | builder => sub { | ||||||||
|
Subroutine
_build_dynamic_config: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 59 | 0 | my $self = shift @_; | |||||||||
| 60 | |||||||||||
| 61 | my @config = | ||||||||||
| 62 | 0 | map { $_->gitstore_config_provided } | |||||||||
| 63 | $self->_dzil->plugins_with('-GitStore::ConfigProvider')->flatten | ||||||||||
| 64 | ; | ||||||||||
| 65 | |||||||||||
| 66 | ### @config | ||||||||||
| 67 | 0 | return \@config; | |||||||||
| 68 | }, | ||||||||||
| 69 | 4 | handles => { | |||||||||
| 70 | has_dynamic_config => 'count', | ||||||||||
| 71 | has_no_dynamic_config => 'is_empty', # XXX ? | ||||||||||
| 72 | has_dynamic_config_for => 'exists', | ||||||||||
| 73 | # ... | ||||||||||
| 74 | }, | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | has store_config => ( | ||||||||||
| 79 | traits => [ 'Hash' ], | ||||||||||
| 80 | is => 'lazy', | ||||||||||
| 81 | isa => 'HashRef', | ||||||||||
| 82 | 0 | ▶ | builder => sub { { } }, | ||||||||
|
Subroutine
_build_store_config: not called CC=1 SCAR=6.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 83 | 4 | handles => { | |||||||||
| 84 | has_store_config => 'count', | ||||||||||
| 85 | has_no_store_config => 'is_empty', # XXX ? | ||||||||||
| 86 | has_store_config_for => 'exists', | ||||||||||
| 87 | # ... | ||||||||||
| 88 | }, | ||||||||||
| 89 | ); | ||||||||||
| 90 | |||||||||||
| 91 | |||||||||||
| 92 | has config => ( | ||||||||||
| 93 | traits => [ 'Hash' ], | ||||||||||
| 94 | is => 'lazy', | ||||||||||
| 95 | isa => 'HashRef', | ||||||||||
| 96 | clearer => -1, # private | ||||||||||
| 97 | |||||||||||
| 98 | handles => { | ||||||||||
| 99 | has_config => 'count', | ||||||||||
| 100 | has_no_config => 'is_empty', | ||||||||||
| 101 | has_config_for => 'exists', | ||||||||||
| 102 | get_config_for => 'get', | ||||||||||
| 103 | # ... | ||||||||||
| 104 | |||||||||||
| 105 | # stopgaps... | ||||||||||
| 106 | has_version_regexp => [ exists => 'version.regexp' ], | ||||||||||
| 107 | version_regexp => [ get => 'version.regexp' ], | ||||||||||
| 108 | has_first_version => [ exists => 'version.first' ], | ||||||||||
| 109 | first_version => [ get => 'version.first' ], | ||||||||||
| 110 | }, | ||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | builder => sub { | ||||||||
|
Subroutine
_build_config: not called CC=1 SCAR=6.9
| |||||||||||
| 113 | 0 | my $self = shift @_; | |||||||||
| 114 | |||||||||||
| 115 | ### merge all our different config sources.. | ||||||||||
| 116 | 0 | my $config = merge | |||||||||
| 117 | $self->default_config, | ||||||||||
| 118 | $self->dynamic_config, | ||||||||||
| 119 | $self->store_config, | ||||||||||
| 120 | ; | ||||||||||
| 121 | |||||||||||
| 122 | 0 | return $config; | |||||||||
| 123 | }, | ||||||||||
| 124 | 4 | ); | |||||||||
| 125 | |||||||||||
| 126 | |||||||||||
| 127 | 4 | related_class 'Git::Wrapper'; | |||||||||
| 128 | |||||||||||
| 129 | has repo_wrapper => ( | ||||||||||
| 130 | is => 'lazy', | ||||||||||
| 131 | isa_instance_of => 'Git::Wrapper', | ||||||||||
| 132 | 0 | ▶ | builder => sub { $_[0]->git__wrapper_class->new($_[0]->repo_root) }, | ||||||||
|
Subroutine
_build_repo_wrapper: not called CC=1 SCAR=6.9
| |||||||||||
| 133 | 4 | ); | |||||||||
| 134 | |||||||||||
| 135 | |||||||||||
| 136 | 4 | related_class 'Git::Raw::Repository'; | |||||||||
| 137 | |||||||||||
| 138 | has repo_raw => ( | ||||||||||
| 139 | is => 'lazy', | ||||||||||
| 140 | isa_instance_of => 'Git::Raw::Repository', | ||||||||||
| 141 | 0 | ▶ | builder => sub { $_[0]->git__raw__repository_class->open($_[0]->repo_root) }, | ||||||||
|
Subroutine
_build_repo_raw: not called CC=1 SCAR=6.9
| |||||||||||
| 142 | 4 | ); | |||||||||
| 143 | |||||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | has repo_root => (is => 'lazy', builder => sub { '.' }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 146 | |||||||||||
| 147 | |||||||||||
| 148 | has tags => ( | ||||||||||
| 149 | is => 'lazy', | ||||||||||
| 150 | isa => 'ArrayRef[Str]', | ||||||||||
| 151 | # For win32, natch | ||||||||||
| 152 | 0 | ▶ | builder => sub { local $/ = "\n"; [ shift->repo_wrapper->tag ] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 153 | 4 | ); | |||||||||
| 154 | |||||||||||
| 155 | |||||||||||
| 156 | has previous_versions => ( | ||||||||||
| 157 | |||||||||||
| 158 | traits => ['Array'], | ||||||||||
| 159 | is => 'lazy', | ||||||||||
| 160 | isa => 'ArrayRef[Str]', | ||||||||||
| 161 | |||||||||||
| 162 | handles => { | ||||||||||
| 163 | |||||||||||
| 164 | has_previous_versions => 'count', | ||||||||||
| 165 | earliest_version => [ get => 0 ], | ||||||||||
| 166 | latest_version => [ get => -1 ], | ||||||||||
| 167 | }, | ||||||||||
| 168 | |||||||||||
| 169 | 0 | ▶ | builder => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 170 | 0 | my $self = shift @_; | |||||||||
| 171 | |||||||||||
| 172 | 0 | my $regexp = $self->version_regexp; | |||||||||
| 173 | 0 | ▶ | my @tags = map { /$regexp/ ? $1 : () } $self->tags->flatten; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 174 | |||||||||||
| 175 | # find tagged versions; sort least to greatest | ||||||||||
| 176 | my @versions = | ||||||||||
| 177 | 0 | sort { version->parse($a) <=> version->parse($b) } | |||||||||
| 178 | 0 | grep { eval { version->parse($_) } } | |||||||||
| 179 | @tags; | ||||||||||
| 180 | |||||||||||
| 181 | 0 | return [ @versions ]; | |||||||||
| 182 | }, | ||||||||||
| 183 | 4 | ); | |||||||||
| 184 | |||||||||||
| 185 | # -- role implementation | ||||||||||
| 186 | |||||||||||
| 187 | # XXX should this be here as default logic? or should we require that a | ||||||||||
| 188 | # plugin supply this information to us? | ||||||||||
| 189 | |||||||||||
| 190 | 0 | ▶ | sub _default_next_version { | ||||||||
|
Subroutine
_default_next_version: not called CC=3 SCAR=24.8
| |||||||||||
| 191 | 0 | my $self = shift @_; | |||||||||
| 192 | |||||||||||
| 193 | # override (or maybe needed to initialize) | ||||||||||
| 194 | return $ENV{V} | ||||||||||
| 195 | 0 | ▶ | if defined $ENV{V}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | |||||||||||
| 197 | 0 | ▶ | return $self->first_version | ||||||||
|
Branch: 1 branch
| |||||||||||
| 198 | unless $self->has_previous_versions; | ||||||||||
| 199 | |||||||||||
| 200 | 0 | my $last_ver = $self->last_version; | |||||||||
| 201 | 0 | my $new_ver = Version::Next::next_version($last_ver); | |||||||||
| 202 | 0 | $self->log("Bumping version from $last_ver to $new_ver"); | |||||||||
| 203 | |||||||||||
| 204 | 0 | return "$new_ver"; | |||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | |||||||||||
| 208 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 209 | 4 | !!42; | |||||||||
| 210 | |||||||||||
| 211 | __END__ | ||||||||||