File Coverage

blib/lib/Dist/Iller/DocType/Gitignore.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 0 4 0.0
total 32 36 88.8


line stmt bran cond sub pod time code
1 1     1   823 use 5.10.0;
  1         4  
2 1     1   8 use strict;
  1         2  
  1         31  
3 1     1   7 use warnings;
  1         3  
  1         75  
4              
5             package Dist::Iller::DocType::Gitignore;
6              
7             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
8             # ABSTRACT: Turn the Dist::Iller config into a .gitignore file
9             our $VERSION = '0.1409';
10              
11 1     1   7 use Dist::Iller::Elk;
  1         3  
  1         10  
12 1     1   2362 use Path::Tiny;
  1         2  
  1         76  
13 1     1   8 use Types::Standard qw/ArrayRef Str/;
  1         2  
  1         10  
14             with qw/
15             Dist::Iller::DocType
16             /;
17              
18             for my $setting (qw/always onexist/) {
19             has $setting => (
20             is => 'ro',
21             isa => ArrayRef[Str],
22             traits => ['Array'],
23             default => sub { [ ] },
24             handles => {
25             "add_$setting" => 'push',
26             "all_$setting" => 'elements',
27             "get_$setting" => 'get',
28             "set_$setting" => 'set',
29             },
30             );
31             }
32              
33 4     4 0 17 sub comment_start { '#' }
34              
35 3     3 0 44 sub filename { '.gitignore' }
36              
37 4     4 0 29 sub phase { 'after' }
38              
39             sub to_hash {
40 1     1 0 2 my $self = shift;
41 1         33 return { always => $self->always, onexist => $self->onexist };
42             }
43              
44             sub parse {
45             my $self = shift;
46             my $yaml = shift;
47              
48             if(exists $yaml->{'config'}) {
49             # ugly hack..
50             $self->parse_config({ '+config' => $yaml->{'config'} });
51             }
52             if(exists $yaml->{'always'}) {
53             $self->add_always($_) for @{ $yaml->{'always'} };
54             }
55             if(exists $yaml->{'onexist'}) {
56             $self->add_onexist($_) for grep { path($_)->exists } @{ $yaml->{'onexist'} };
57             }
58              
59             if ($self->global && $self->global->has_distribution_name) {
60             for my $type (qw/always onexist/) {
61             my $all = "all_$type";
62             my $get = "get_$type";
63             my $set = "set_$type";
64             for my $index (0.. scalar $self->$all - 1) {
65             my $item = $self->$get($index);
66             $self->$set($index, '/'.$self->global->distribution_name.'-*') if $item eq '$self.distribution_name';
67             }
68             }
69             }
70             }
71              
72             sub to_string {
73             my $self = shift;
74              
75             return join "\n", ($self->all_always, $self->all_onexist, '');
76             }
77              
78             __PACKAGE__->meta->make_immutable;
79              
80             1;
81              
82             __END__
83              
84             =pod
85              
86             =encoding UTF-8
87              
88             =head1 NAME
89              
90             Dist::Iller::DocType::Gitignore - Turn the Dist::Iller config into a .gitignore file
91              
92             =head1 VERSION
93              
94             Version 0.1409, released 2020-12-27.
95              
96             =head1 SOURCE
97              
98             L<https://github.com/Csson/p5-Dist-Iller>
99              
100             =head1 HOMEPAGE
101              
102             L<https://metacpan.org/release/Dist-Iller>
103              
104             =head1 AUTHOR
105              
106             Erik Carlsson <info@code301.com>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2016 by Erik Carlsson.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut