| 1 | package Minilla::Gitignore; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | has lines => ( | ||||||||||
| 9 | is => 'rw', | ||||||||||
| 10 | 0 | ▶ | default => sub { +[ ] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 11 | 1 | ); | |||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | no Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub load { | ||||||||
|
Subroutine
load: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 16 | 0 | my ($class, $filename) = @_; | |||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | open my $fh, '<', $filename | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | or die "Cannot open $filename: $!"; | ||||||||||
| 20 | 0 | my @lines; | |||||||||
| 21 | 0 | ▶ | while (defined($_ = <$fh>)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | chomp; | |||||||||
| 23 | 0 | push @lines, $_; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 0 | return $class->new( | |||||||||
| 27 | lines => [@lines], | ||||||||||
| 28 | ); | ||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | sub remove { | ||||||||
|
Subroutine
remove: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 32 | 0 | my ($self, $pattern) = @_; | |||||||||
| 33 | 0 | ▶ | if (ref $pattern) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $self->lines([grep { $_ !~ $pattern } @{$self->lines}]); | |||||||||
| 35 | } else { | ||||||||||
| 36 | 0 | $self->lines([grep { $_ ne $pattern } @{$self->lines}]); | |||||||||
| 37 | } | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub add { | ||||||||
|
Subroutine
add: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 41 | 0 | my ($self, $pattern) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | unless (grep { $pattern eq $_ } @{$self->lines}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | push @{$self->lines}, $pattern; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 49 | 0 | my $self = shift; | |||||||||
| 50 | 0 | return join('', map { "$_\n" } @{$self->lines}); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub save { | ||||||||
|
Subroutine
save: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 54 | 0 | my ($self, $filename) = @_; | |||||||||
| 55 | 0 | ▶ | open my $fh, '>', $filename | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | or die "Cannot open $filename: $!"; | ||||||||||
| 57 | 0 | for (@{$self->lines}) { | |||||||||
| 58 | 0 | print {$fh} $_, "\n"; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | close $fh; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 1 | 1; | |||||||||
| 64 | |||||||||||