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.99';
7 12     12   74 use Moose;
  12         25  
  12         381  
8             with 'HiD::Role::IsPublished';
9 12     12   80145 use namespace::autoclean;
  12         30  
  12         104  
10              
11 12     12   1067 use 5.014; # strict, unicode_strings
  12         48  
12 12     12   57 use utf8;
  12         38  
  12         74  
13 12     12   301 use autodie;
  12         23  
  12         80  
14 12     12   54581 use warnings qw/ FATAL utf8 /;
  12         26  
  12         529  
15 12     12   64 use open qw/ :std :utf8 /;
  12         22  
  12         93  
16 12     12   1720 use charnames qw/ :full /;
  12         31  
  12         89  
17              
18 12     12   2532 use Path::Tiny;
  12         28  
  12         2886  
19              
20              
21             sub publish {
22 27     27 1 974 my $self = shift;
23              
24 27         732 my $out = path( $self->output_filename );
25 27         706 my $dir = $out->parent;
26              
27 27 100       1609 $dir->mkpath unless $dir->is_dir;
28              
29 27 50       1755 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   49 my $self = shift;
36              
37 27         702 my $source = $self->source;
38              
39 27         627 my $path_frag = $self->input_filename;
40 27         211 $path_frag =~ s/^$source//;
41              
42 27         98 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.99
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