File Coverage

blib/lib/Dist/Zilla/Plugin/TextTabs.pm
Criterion Covered Total %
statement 25 25 100.0
branch 10 10 100.0
condition n/a
subroutine 6 6 100.0
pod 0 3 0.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::TextTabs;
2              
3 5     5   4223940 use Moose;
  5         575042  
  5         45  
4 5     5   46060 use Text::Tabs qw( expand unexpand );
  5         4490  
  5         562  
5              
6             # ABSTRACT: Expand or unexpand tabs in your dist
7             our $VERSION = '0.03'; # VERSION
8              
9              
10             with 'Dist::Zilla::Role::FileMunger',
11             'Dist::Zilla::Role::FileFinderUser' => {
12             default_finders => [ ':InstallModules', ':ExecFiles' ],
13             },
14             'Dist::Zilla::Role::InstallTool',
15             ;
16              
17 5     5   1040 use namespace::autoclean;
  5         1760  
  5         57  
18              
19             has tabstop => (
20             is => 'ro',
21             isa => 'Int',
22             default => 8,
23             );
24              
25             has unexpand => (
26             is => 'ro',
27             isa => 'Bool',
28             default => 0,
29             );
30              
31             has installer => (
32             is => 'ro',
33             isa => 'Bool',
34             default => 0,
35             );
36              
37             sub munge_files
38             {
39 4     4 0 286448 my($self) = @_;
40 4 100       199 return if $self->installer;
41 3         9 $self->munge_file($_) for @{ $self->found_files };
  3         23  
42             }
43              
44             sub munge_file
45             {
46 4     4 0 10602 my($self, $file) = @_;
47 4 100       199 $self->log(($self->unexpand ? 'un' : '') . 'expanding ' . $file->name);
48 4         1803 local $Text::Tabs::tabstop = $self->tabstop;
49 4 100       33 $file->content(join("\n", map { $self->unexpand ? unexpand $_ : expand $_ } split /\n/, $file->content));
  28         8470  
50 4         947 return;
51             }
52              
53             sub setup_installer
54             {
55 4     4 0 39405 my($self) = @_;
56 4 100       208 return unless $self->installer;
57 1         3 foreach my $file (@{ $self->zilla->files })
  1         48  
58             {
59 3 100       184 next unless $file->name =~ /^(Makefile|Build).PL$/;
60 1         20 $self->munge_file($file);
61             }
62             }
63              
64             __PACKAGE__->meta->make_immutable;
65              
66             1;
67              
68             __END__
69              
70             =pod
71              
72             =encoding UTF-8
73              
74             =head1 NAME
75              
76             Dist::Zilla::Plugin::TextTabs - Expand or unexpand tabs in your dist
77              
78             =head1 VERSION
79              
80             version 0.03
81              
82             =head1 SYNOPSIS
83              
84             [TextTabs]
85             tabstop = 8
86             unexapand = 0
87              
88             =head1 DESCRIPTION
89              
90             This L<Dist::Zilla> plugin expands or unexpands tabs using L<Text::Tab>.
91              
92             =head1 ATTRIBUTES
93              
94             =head2 tabstop
95              
96             The length of the tabstop in characters. This is usually 8, but some people prefer 4 or 2.
97              
98             =head2 unexpand
99              
100             if set to true, then an unexpand is used on all the targeted files, that is spaces of the
101             right length are converted into an equivalent number of tabs. The default is false, or
102             expand mode.
103              
104             =head2 installer
105              
106             Instead of doing its work during the usual file munger stage, if this
107             attribute is true (the default is false), then this plugin will munge
108             just the C<Makefile.PL> or C<Build.PL> (or both if you have both) files
109             during the C<InstallTool> phase. This allows you to remove nauty
110             tabs from the installer than may have been put there by a nauty
111             C<InstallTool> plugin (take care to put C<[TextTabs]> in your C<dist.ini>
112             after the nauty installer plugin).
113              
114             =head1 SEE ALSO
115              
116             L<Text::Tabs>
117              
118             =head1 AUTHOR
119              
120             Graham Ollis <plicease@cpan.org>
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2013 by Graham Ollis.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =cut