blib/lib/Dist/Zilla/Role/Git/StringFormatter.pm

filter: Statementstmt 93.5% 58 / 62 Branchbran 60.0% 6 / 10 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 84.2% 16 / 19 Podpod n/a totaltotal 85.1% 80 / 94 CC 7 SCAR 11.8
CC
7
Cov
86%
__ANON__
12.0
__ANON__
6.0
_get_changes
4.0
CRAP 3.2
« blib/lib/Dist/Zilla/Plugin/Git/Commit.pm ↑ Summary blib/lib/Dist/Zilla/PluginBundle/Git.pm »
1 #
2 # This file is part of Dist-Zilla-Plugin-Git
3 #
4 # This software is copyright (c) 2009 by Jerome Quelin.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Dist::Zilla::Role::Git::StringFormatter;
10 # ABSTRACT: Provide a String::Formatter for commit messages
11  
12 11 our $VERSION = '2.052';
13  
14 11 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use List::Util qw{ first };
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 11 ▶use Types::Standard qw{ Str };
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 11 requires qw(changelog log zilla);
25  
26 11 ▶use String::Formatter method_stringf => {
Subroutine BEGIN: called CC=1 SCAR=1.4
27 -as => '_format_string_sub',
28 codes => {
29 20 ▶ c => sub { $_[0]->_get_changes },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 0 ▶ d => sub { require DateTime;
Subroutine __ANON__: not called CC=2 SCAR=17.9
31 0 ▶ DateTime->now(time_zone => $_[0]->time_zone)
Condition0%0/2
$_[1] || 'dd-MMM-yyyy'
l!l
00
MC/DC0%0/1
$_[1] || 'dd-MMM-yyyy'
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
32 ->format_cldr($_[1] || 'dd-MMM-yyyy') },
33 40 ▶ n => sub { "\n" },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 0 ▶ N => sub { $_[0]->zilla->name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ t => sub { $_[0]->zilla->is_trial
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->zilla->is_trial ? : 0 0 0
defined $_[1] ? : 0 0 0
36 ? (defined $_[1] ? $_[1] : '-TRIAL') : '' },
37 1 ▶ v => sub { $_[0]->zilla->version },
Subroutine __ANON__: called CC=1 SCAR=0.0
38 28 ▶ V => sub { my $v = $_[0]->zilla->version; $v =~ s/\Av//; $v },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 },
40 11 };
41  
42 #pod =attr changelog
43 #pod
44 #pod The filename of your F<Changes> file. (Must be provided by the class
45 #pod that consumes this role.)
46 #pod
47 #pod =attr time_zone
48 #pod
49 #pod The time zone used with the C<%d> code. The default is C<local>.
50 #pod
51 #pod =cut
52  
53 11 has time_zone => ( is => 'ro', isa=>Str, default => 'local' );
54  
55 around dump_config => sub
56 17 ▶{
Subroutine __ANON__: called CC=1 SCAR=0.0
57 17 my $orig = shift;
58 17 my $self = shift;
59  
60 17 my $config = $self->$orig;
61 17 $config->{+__PACKAGE__} = {
62 time_zone => $self->time_zone,
63 };
64  
65 17 return $config;
66 11 };
67  
68 # -- private methods
69  
70 # The sub generated by String::Formatter can't be used as a method directly.
71 sub _format_string
72 29 ▶{
Subroutine _format_string: called CC=1 SCAR=0.0
73 29 my $self = shift;
74  
75 29 _format_string_sub(@_, $self);
76 } # end _format_string
77  
78 20 ▶sub _get_changes {
Subroutine _get_changes: called CC=4 SCAR=13.9
79 20 my $self = shift;
80  
81 # parse changelog to find changes for this release
82 20 my $cl_name = $self->changelog;
83 20 ▶ my $changelog = first { $_->name eq $cl_name } @{ $self->zilla->files };
Subroutine __ANON__: called CC=1 SCAR=0.0
84 20 ▶ unless ($changelog) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($changelog) 1 19 20
85 1 $self->log("WARNING: Unable to find $cl_name");
86 1 return '';
87 }
88 19 my $newver = $self->zilla->version;
89 $changelog->content =~ /
90 ^\Q$newver\E(?![_.]*[0-9]).*\n # from line beginning with version number
91 ( (?: (?> .* ) (?:\n|\z) )*? ) # capture as few lines as possible
92 (?: (?> \s* ) ^\S | \z ) # until non-indented line or EOF
93 19 ▶ /xm or do {
Branch: 1 branch
BranchTrueFalseTotal
$changelog->content =~ / ^\Q$newver\E(?![_.]*[0-9]).*\n # from line beginning with version number ( (?: (?> .* ) (?:\n|\z) )*? ) # capture as few lines as possible (?: (?> \s* ) ^\S | \z ) # until non-indented line or EOF /mx or do { $self->log("WARNING: Unable to find $newver in $cl_name"); return "" } 18 1 19
94 1 $self->log("WARNING: Unable to find $newver in $cl_name");
95 1 return '';
96 };
97  
98 18 (my $changes = $1) =~ s/^\s*\n//; # Remove leading blank lines
99  
100 18 ▶ if (length $changes) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $changes) { } 17 1 18
101 17 $changes =~ s/\s*\z/\n/; # Change trailing whitespace to a single newline
102 } else {
103 1 $self->log("WARNING: No changes listed under $newver in $cl_name")
104 }
105  
106 # return changes
107 18 return $changes;
108 } # end _get_changes
109  
110 11 1;
111  
112 __END__
« blib/lib/Dist/Zilla/Plugin/Git/Commit.pm ↑ Summary blib/lib/Dist/Zilla/PluginBundle/Git.pm »