File Coverage

blib/lib/HTML/Spelling/Site/Finder.pm
Criterion Covered Total %
statement 26 30 86.6
branch 1 6 16.6
condition 0 3 0.0
subroutine 8 8 100.0
pod 1 1 100.0
total 36 48 75.0


line stmt bran cond sub pod time code
1             package HTML::Spelling::Site::Finder;
2             $HTML::Spelling::Site::Finder::VERSION = '0.10.2';
3 1     1   245415 use strict;
  1         9  
  1         30  
4 1     1   5 use warnings;
  1         2  
  1         24  
5              
6 1     1   18 use 5.014;
  1         4  
7              
8 1     1   7 use MooX (qw( late ));
  1         2  
  1         7  
9              
10 1     1   1789 use File::Find::Object ();
  1         8906  
  1         151  
11              
12             has 'prune_cb' => ( is => 'ro', isa => 'CodeRef', default => sub { return; } );
13             has 'root_dir' => ( is => 'ro', isa => 'Str', 'required' => 1, );
14              
15             sub list_all_htmls
16             {
17 1     1 1 8590 my ($self) = @_;
18              
19 1         13 my $f = File::Find::Object->new( {}, $self->root_dir );
20              
21 1         243 my @got;
22 1         5 while ( my $r = $f->next_obj() )
23             {
24 0         0 my $path = $r->path;
25 0 0 0     0 if ( $self->prune_cb->($path) )
    0          
26             {
27 0         0 $f->prune;
28             }
29             elsif ( $r->is_file and $r->basename =~ /\.x?html\z/ )
30             {
31 0         0 push @got, $path;
32             }
33             }
34 1     1   476 use locale;
  1         590  
  1         7  
35 1     1   548 use POSIX qw(locale_h strtod);
  1         6354  
  1         5  
36 1 50       162 setlocale( LC_COLLATE, 'C' ) or die "cannot set locale.";
37              
38 1         74 return [ sort @got ];
39             }
40              
41             1;
42              
43             __END__
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             HTML::Spelling::Site::Finder - find the relevant .html/.xhtml files in
52             a directory tree.
53              
54             =head1 VERSION
55              
56             version 0.10.2
57              
58             =head1 SYNOPSIS
59              
60             use HTML::Spelling::Site::Finder;
61              
62             my $finder = HTML::Spelling::Site::Finder->new(
63             {
64             prune_cb => sub {
65             return (shift =~ m#\Adest/blacklist/#);
66             },
67             root_dir => 'dest/',
68             }
69             );
70              
71             foreach my $html_file (@{$finder->list_all_htmls()})
72             {
73             print "Should check <$html_file>.\n";
74             }
75              
76             =head1 DESCRIPTION
77              
78             The instances of this class can be used to scan a directory tree of files
79             ending with C<.html> and C<.xhtml> and to return a list of them as a sorted
80             array reference.
81              
82             =head1 METHODS
83              
84             =head2 ->new({ prune_cb => sub { ... }, root_dir => $root_dir })
85              
86             Initialises a new object. C<prune_cb> is optional and C<root_dir> is required
87             and is the path to the root of the directory to scan.
88              
89             =head2 my $array_ref = $finder->list_all_htmls()
90              
91             Returns an array reference of all HTML files, sorted.
92              
93             =head2 $finder->prune_cb()
94              
95             Returns the prune callback. Mostly for internal use.
96              
97             =head2 $finder->root_dir()
98              
99             Returns the root directory.
100              
101             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
102              
103             =head1 SUPPORT
104              
105             =head2 Websites
106              
107             The following websites have more information about this module, and may be of help to you. As always,
108             in addition to those websites please use your favorite search engine to discover more resources.
109              
110             =over 4
111              
112             =item *
113              
114             MetaCPAN
115              
116             A modern, open-source CPAN search engine, useful to view POD in HTML format.
117              
118             L<https://metacpan.org/release/HTML-Spelling-Site>
119              
120             =item *
121              
122             RT: CPAN's Bug Tracker
123              
124             The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
125              
126             L<https://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Spelling-Site>
127              
128             =item *
129              
130             CPANTS
131              
132             The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
133              
134             L<http://cpants.cpanauthors.org/dist/HTML-Spelling-Site>
135              
136             =item *
137              
138             CPAN Testers
139              
140             The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
141              
142             L<http://www.cpantesters.org/distro/H/HTML-Spelling-Site>
143              
144             =item *
145              
146             CPAN Testers Matrix
147              
148             The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
149              
150             L<http://matrix.cpantesters.org/?dist=HTML-Spelling-Site>
151              
152             =item *
153              
154             CPAN Testers Dependencies
155              
156             The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
157              
158             L<http://deps.cpantesters.org/?module=HTML::Spelling::Site>
159              
160             =back
161              
162             =head2 Bugs / Feature Requests
163              
164             Please report any bugs or feature requests by email to C<bug-html-spelling-site at rt.cpan.org>, or through
165             the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=HTML-Spelling-Site>. You will be automatically notified of any
166             progress on the request by the system.
167              
168             =head2 Source Code
169              
170             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
171             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
172             from your repository :)
173              
174             L<https://github.com/shlomif/HTML-Spelling-Site>
175              
176             git clone https://github.com/shlomif/HTML-Spelling-Site.git
177              
178             =head1 AUTHOR
179              
180             Shlomi Fish <shlomif@cpan.org>
181              
182             =head1 BUGS
183              
184             Please report any bugs or feature requests on the bugtracker website
185             L<https://github.com/shlomif/html-spelling-site/issues>
186              
187             When submitting a bug or request, please include a test-file or a
188             patch to an existing test-file that illustrates the bug or desired
189             feature.
190              
191             =head1 COPYRIGHT AND LICENSE
192              
193             This software is Copyright (c) 2016 by Shlomi Fish.
194              
195             This is free software, licensed under:
196              
197             The MIT (X11) License
198              
199             =cut