| 1 | package App::Changelord::Role::GitRepo; | ||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | 5 | $App::Changelord::Role::GitRepo::VERSION = '0.0.2'; | |||||||||
| 4 | 5 | ▶ | use v5.36.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | ▶ | use Git::Repository; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 5 | ▶ | use feature 'try'; no warnings qw/ experimental /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 5 | requires 'changelog'; | |||||||||
| 13 | |||||||||||
| 14 | # stolen from Dist::Zilla::Plugin::ChangeStats::Git | ||||||||||
| 15 | |||||||||||
| 16 | has repo => ( | ||||||||||
| 17 | is => 'lazy', | ||||||||||
| 18 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | 0 | Git::Repository->new( work_tree => '.' ) | |||||||||
| 20 | }, | ||||||||||
| 21 | 5 | ); | |||||||||
| 22 | |||||||||||
| 23 | 5 | has stats => ( is => 'lazy' ); | |||||||||
| 24 | |||||||||||
| 25 | 1 | ▶ | sub _build_stats ($self) { | ||||||||
|
Subroutine
_build_stats: called CC=2 SCAR=7.1
| |||||||||||
| 26 | 1 | ▶ | my $comparison_data = $self->_get_comparison_data or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | |||||||||||
| 28 | 1 | my $stats = 'code churn: ' . $comparison_data; | |||||||||
| 29 | 1 | return $stats =~ s/\s+/ /gr; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 1 | ▶ | sub _get_comparison_data($self) { | ||||||||
|
Subroutine
_get_comparison_data: called CC=3 SCAR=11.3
| |||||||||||
| 33 | |||||||||||
| 34 | # HEAD versus previous release | ||||||||||
| 35 | # What are we diffing against? :) | ||||||||||
| 36 | my $previous = $self->changelog->{releases}->@* > 1 | ||||||||||
| 37 | ? $self->changelog->{releases}[1]{version} | ||||||||||
| 38 | 1 | ▶ | : '4b825dc642cb6eb9a060e54bf8d69288fbee4904'; # empty tree | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 1 | my $output = eval { | |||||||||
| 41 | 1 | $self->repo->run( 'diff', '--shortstat', $previous, 'HEAD') | |||||||||
| 42 | }; | ||||||||||
| 43 | |||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | warn "could not gather stats: $@\n" if $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 1 | return $output; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 5 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||