File Coverage

blib/lib/App/Embra/Plugin/PublishFiles.pm
Criterion Covered Total %
statement 31 31 100.0
branch 6 10 60.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 46 50 92.0


line stmt bran cond sub pod time code
1 1     1   383 use strict;
  1         1  
  1         45  
2 1     1   4 use warnings;
  1         1  
  1         37  
3              
4             package App::Embra::Plugin::PublishFiles;
5             $App::Embra::Plugin::PublishFiles::VERSION = '0.001'; # TRIAL
6             # ABSTRACT: write site files into a directory
7              
8 1     1   374 use Path::Class qw<>;
  1         31709  
  1         38  
9 1     1   9 use Method::Signatures;
  1         2  
  1         10  
10 1     1   470 use Moo;
  1         1  
  1         7  
11              
12              
13              
14             has 'to' => (
15             is => 'ro',
16             required => 1,
17 1 50   1   2965 default => '.',
  1     1   29  
  1         4  
18 1         1 coerce => func( $path_as_str ) { Path::Class::dir( $path_as_str ) },
  1         7  
19 2         73 );
20 2         238  
21 2         273 method publish_site {
22 2 50       971 for my $file ( @{ $self->embra->files } ) {
23             my $f = $self->to->file( $file->name );
24             $f->parent->mkpath;
25             $f->spew( $file->content );
26 1 50   1   1783 chmod $file->mode, $f or die "could't chmod $file: $!";
  3 50   3   4  
  3         7  
  3         2  
  3         7  
27 3 100       19 }
28 2         622 }
29              
30             method exclude_file( $file ) {
31             return 1 if $self->to->subsumes( $file->name );
32             return;
33             }
34              
35             with 'App::Embra::Role::SitePublisher';
36             with 'App::Embra::Role::FilePruner';
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             App::Embra::Plugin::PublishFiles - write site files into a directory
49              
50             =head1 VERSION
51              
52             version 0.001
53              
54             =head1 DESCRIPTION
55              
56             This plugin creates your site in a directory. The name of each file is used as the path to write its content to, relative to the destination directory.
57              
58             This plugin additionally prunes already-published files from the list of files to include in the site. This is useful if your L<App::Embra::Role::FileGather> plugins find the L</to> directory and add the previous version of the published site to be re-published.
59              
60             =head1 ATTRIBUTES
61              
62             =head2 to
63              
64             The directory where site files will be written. Defaults to F<.> (the current directory).
65              
66             =head1 AUTHOR
67              
68             Daniel Holz <dgholz@gmail.com>
69              
70             =head1 COPYRIGHT AND LICENSE
71              
72             This software is copyright (c) 2015 by Daniel Holz.
73              
74             This is free software; you can redistribute it and/or modify it under
75             the same terms as the Perl 5 programming language system itself.
76              
77             =cut