Readme/Plugin/version.pm

filter: Statementstmt 95.3% 41 / 43 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 88.5% 54 / 61 CC 6 SCAR 12.3
CC
6
Cov
88%
cmd_version
6.6
BEGIN
1.0
BEGIN
1.0
CRAP 3.4
« Readme/Plugin.pm ↑ Summary Readme.pm »
1 package Pod::Readme::Plugin::version;
2  
3 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 our $VERSION = 'v1.2.3';
6  
7 1 ▶use ExtUtils::MakeMaker;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Types::Standard qw/ Bool Str /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Pod::Readme::Types qw/ File HeadingLevel /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Pod::Readme::Plugin::version - Include version in README
15  
16 =head1 SYNOPSIS
17  
18 =for readme plugin version
19  
20 =head1 DESCRIPTION
21  
22 This is a plugin for L<Pod::Readme> that includes the release version.
23  
24 =head1 ARGUMENTS
25  
26 =head2 C<file>
27  
28 =for readme plugin version file='lib/My/App.pm'
29  
30 By default, it will extract the version from the same file that the
31 F<README> is being extracted from. If this is a different file, then
32 it should be specified.
33  
34 =head2 C<title>
35  
36 =for readme plugin version title='VERSION'
37  
38 This argument allows you to change the title of the heading.
39  
40 =cut
41  
42 1 requires 'parse_cmd_args';
43  
44 has 'version_file' => (
45 is => 'rw',
46 isa => File,
47 required => 0,
48 2 ▶ coerce => sub { File->coerce(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 lazy => 1,
50 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 my ($self) = @_;
52 1 $self->input_file;
53 },
54 1 );
55  
56 1 has 'version_title' => (
57 is => 'rw',
58 isa => Str,
59 default => 'VERSION',
60 lazy => 1,
61 );
62  
63 1 has 'version_heading_level' => (
64 is => 'rw',
65 isa => HeadingLevel,
66 default => 1,
67 lazy => 1,
68 );
69  
70 1 has 'version_run' => (
71 is => 'rw',
72 isa => Bool,
73 default => 0,
74 lazy => 1,
75 );
76  
77 2 ▶around 'depends_on' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
78 2 my ($orig, $self) = @_;
79 2 return ($self->version_file, $self->$orig);
80 1 };
81  
82 3 ▶sub cmd_version {
Subroutine cmd_version: called CC=6 SCAR=18.9
Pod undocumented
83 3 my ( $self, @args ) = @_;
84  
85 3 ▶ die "The version plugin can only be used once" if $self->version_run;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version_run 0 3 3
86  
87 3 my $res = $self->parse_cmd_args( [qw/ file title heading-level /], @args );
88 3 foreach my $key ( keys %{$res} ) {
89 4 ( my $name = "version_${key}" ) =~ s/-/_/g;
90 4 ▶ if ( my $method = $self->can($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $self->can($name)) { } 4 0 4
91 4 $self->$method( $res->{$key} );
92 }
93 else {
94 0 die "Invalid key: '${key}'";
95 }
96 }
97  
98 3 ▶ if ( my $file = $self->version_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->version_file) { } 3 0 3
99  
100 3 ▶ my $heading = $self->can( "write_head" . $self->version_heading_level )
Branch: 1 branch
BranchTrueFalseTotal
my $heading = $self->can('write_head' . $self->version_heading_level) or die 'Invalid heading level: ' . $self->version_heading_level 3 0 3
101 or die "Invalid heading level: " . $self->version_heading_level;
102  
103 3 $self->$heading( $self->version_title );
104 3 $self->write_para( MM->parse_version($file) );
105  
106 3 $self->version_run(1);
107  
108 }
109 else {
110  
111 0 die "Don't know what file to determine the version from";
112  
113 }
114 }
115  
116 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
117  
118 1 1;
« Readme/Plugin.pm ↑ Summary Readme.pm »