File Coverage

blib/lib/HiD/File.pm
Criterion Covered Total %
statement 36 36 100.0
branch 3 4 75.0
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 51 52 98.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Regular files that are only copied, not processed (e.g., CSS, JS, etc.)
2              
3              
4             package HiD::File;
5             our $AUTHORITY = 'cpan:GENEHACK';
6             $HiD::File::VERSION = '1.991';
7 12     12   80 use Moose;
  12         29  
  12         103  
8             with 'HiD::Role::IsPublished';
9 12     12   82910 use namespace::autoclean;
  12         25  
  12         104  
10              
11 12     12   1108 use 5.014; # strict, unicode_strings
  12         39  
12 12     12   62 use utf8;
  12         20  
  12         80  
13 12     12   319 use autodie;
  12         27  
  12         84  
14 12     12   54428 use warnings qw/ FATAL utf8 /;
  12         27  
  12         619  
15 12     12   63 use open qw/ :std :utf8 /;
  12         22  
  12         98  
16 12     12   1701 use charnames qw/ :full /;
  12         33  
  12         80  
17              
18 12     12   2406 use Path::Tiny;
  12         23  
  12         2829  
19              
20              
21             sub publish {
22 27     27 1 822 my $self = shift;
23              
24 27         664 my $out = path( $self->output_filename );
25 27         616 my $dir = $out->parent;
26              
27 27 100       1328 $dir->mkpath unless $dir->is_dir;
28              
29 27 50       1444 path( $self->input_filename )->copy( $out )
30             or die $!;
31             }
32              
33             # used to populate the 'url' attr in Role::IsPublished
34             sub _build_url {
35 27     27   42 my $self = shift;
36              
37 27         546 my $source = $self->source;
38              
39 27         530 my $path_frag = $self->input_filename;
40 27         153 $path_frag =~ s/^$source//;
41              
42 27         83 return path( $path_frag )->stringify;
43             }
44              
45              
46             __PACKAGE__->meta->make_immutable;
47             1;
48              
49             __END__
50              
51             =pod
52              
53             =encoding UTF-8
54              
55             =head1 NAME
56              
57             HiD::File - Regular files that are only copied, not processed (e.g., CSS, JS, etc.)
58              
59             =head1 SYNOPSIS
60              
61             my $file = HiD::File->new({
62             dest_dir => 'directory/for/output'
63             input_filename => $file_filename ,
64             });
65              
66             =head1 DESCRIPTION
67              
68             Object class representing "normal" files (ones that HiD just copies from
69             source to destination, without further processing).
70              
71             =head1 METHODS
72              
73             =head2 publish
74              
75             Publishes (in this case, copies) the input file to the output file.
76              
77             =head1 NOTE
78              
79             Also consumes L<HiD::Role::IsPublished>; see documentation for that role as
80             well if you're trying to figure out how an object from this class works.
81              
82             =head1 VERSION
83              
84             version 1.991
85              
86             =head1 AUTHOR
87              
88             John SJ Anderson <genehack@genehack.org>
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2015 by John SJ Anderson.
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut