File Coverage

blib/lib/Statocles/Deploy/File.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package Statocles::Deploy::File;
2             our $VERSION = '0.085';
3             # ABSTRACT: Deploy a site to a folder on the filesystem
4              
5 58     58   6792 use Statocles::Base 'Class';
  58         131  
  58         761  
6             with 'Statocles::Deploy';
7              
8             #pod =attr path
9             #pod
10             #pod The path to deploy to.
11             #pod
12             #pod =cut
13              
14             has path => (
15             is => 'ro',
16             isa => Path,
17             coerce => Path->coercion,
18             default => sub { Path::Tiny->new( '.' ) },
19             );
20              
21             #pod =method deploy
22             #pod
23             #pod my @paths = $deploy->deploy( $from_store, %options );
24             #pod
25             #pod Deploy the site, copying from the given L<from_store|Statocles::Store>.
26             #pod Returns the paths that were deployed.
27             #pod
28             #pod Possible options are:
29             #pod
30             #pod =over 4
31             #pod
32             #pod =item clean
33             #pod
34             #pod Remove all the current contents of the deploy directory before copying the
35             #pod new content.
36             #pod
37             #pod =back
38             #pod
39             #pod =cut
40              
41             sub deploy {
42 29     29 1 7943 my ( $self, $from_store, %options ) = @_;
43              
44 29 100       321 die sprintf 'Deploy directory "%s" does not exist (did you forget to make it?)',
45             $self->path
46             if !$self->path->is_dir;
47              
48 28 100       758 if ( $options{ clean } ) {
49 2         15 $_->remove_tree for $self->path->children;
50             }
51              
52 28         15018 $self->site->log->info( "Copying files from build dir to deploy dir" );
53 28         2565 my @files;
54 28         235 my $iter = $from_store->find_files( include_documents => 1 );
55 28         121 while ( my $path = $iter->() ) {
56             # Git versions before 1.7.4.1 require a relative path to 'git add'
57 706         203201 push @files, $path->relative( "/" )->stringify;
58 706         136994 $from_store->path->child( $path )->copy( $self->path->child( $path )->touchpath );
59             }
60              
61 28         709 return @files;
62             }
63              
64             1;
65              
66             __END__
67              
68             =pod
69              
70             =encoding UTF-8
71              
72             =head1 NAME
73              
74             Statocles::Deploy::File - Deploy a site to a folder on the filesystem
75              
76             =head1 VERSION
77              
78             version 0.085
79              
80             =head1 DESCRIPTION
81              
82             This class allows a site to be deployed to a folder on the filesystem.
83              
84             This class consumes L<Statocles::Deploy|Statocles::Deploy>.
85              
86             =head1 ATTRIBUTES
87              
88             =head2 path
89              
90             The path to deploy to.
91              
92             =head1 METHODS
93              
94             =head2 deploy
95              
96             my @paths = $deploy->deploy( $from_store, %options );
97              
98             Deploy the site, copying from the given L<from_store|Statocles::Store>.
99             Returns the paths that were deployed.
100              
101             Possible options are:
102              
103             =over 4
104              
105             =item clean
106              
107             Remove all the current contents of the deploy directory before copying the
108             new content.
109              
110             =back
111              
112             =head1 SEE ALSO
113              
114             =over 4
115              
116             =item L<Statocles::Deploy>
117              
118             =back
119              
120             =head1 AUTHOR
121              
122             Doug Bell <preaction@cpan.org>
123              
124             =head1 COPYRIGHT AND LICENSE
125              
126             This software is copyright (c) 2016 by Doug Bell.
127              
128             This is free software; you can redistribute it and/or modify it under
129             the same terms as the Perl 5 programming language system itself.
130              
131             =cut