File Coverage

blib/lib/Directory/Deploy.pm
Criterion Covered Total %
statement 35 38 92.1
branch 1 4 25.0
condition n/a
subroutine 15 15 100.0
pod 0 5 0.0
total 51 62 82.2


line stmt bran cond sub pod time code
1             package Directory::Deploy;
2              
3 4     4   659636 use warnings;
  4         11  
  4         167  
4 4     4   23 use strict;
  4         9  
  4         259  
5              
6             =head1 NAME
7              
8             Directory::Deploy - Create files and directories on disk
9              
10             =head1 VERSION
11              
12             Version 0.003
13              
14             =cut
15              
16             our $VERSION = '0.003';
17              
18             =head1 SYNOPSIS
19              
20             package My::Assets;
21              
22             use Directory::Deploy::Declare;
23              
24             include <<'_END_';
25             # A line beginning with '#' is ignored
26             run/
27             # A path with a trailing slash is a directory (otherwise a file)
28             run/root/
29             run/tmp/:700
30             # A :\d+ after a path is the mode (permissions) for the file/dir
31             assets/
32             assets/root/
33             assets/root/static/
34             assets/root/static/css/
35             assets/root/static/js/
36             assets/tt/
37             _END_
38              
39             include
40             'assets/tt/frame.tt.html' => \<<'_END_',
41             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
42             <html xmlns="http://www.w3.org/1999/xhtml">
43             <head>
44             <title>[% title %]</title>
45             <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
46             </head>
47             <body>
48             <div id="doc2">
49              
50             [% content %]
51              
52             <div class="footer"> ... </div>
53              
54             </div>
55             </body>
56             </html>
57             _END_
58              
59             'assets/root/static/css/base.css' => \<<'_END_',
60             body, table {
61             font-family: Verdana, Arial, sans-serif;
62             background-color: #fff;
63             }
64              
65             a, a:hover, a:active, a:visited {
66             text-decoration: none;
67             font-weight: bold;
68             color: #436b95;
69             }
70             _END_
71             ; # End of the include
72              
73             no Directory::Deploy::Declare;
74              
75             # ... elsewhere ...
76              
77             My::Assets->deploy( { base => $dir } )
78              
79             # ... or ...
80              
81             my $assets = My::Assets->new( base => $dir )
82             $assets->deploy
83              
84             =head1 DESCRIPTION
85              
86             Directory::Deploy is a tool for creating files and directories (on disk)
87              
88             The usage is pretty much as the SYNOPSIS says. Caveat emptor: the interface is Beta(tm) and *might* change
89            
90             =cut
91              
92 4     4   5601 use Moose;
  4         2411245  
  4         40  
93              
94 4     4   35556 use Directory::Deploy::Carp;
  4         16  
  4         31  
95 4     4   2951 use Directory::Deploy::Manifest;
  4         15  
  4         210  
96 4     4   3197 use Directory::Deploy::Maker;
  4         16  
  4         197  
97              
98 4     4   36 use Path::Class();
  4         11  
  4         1474  
99              
100             has manifest => qw/is ro lazy_build 1/, handles => [qw/ add include /];
101             sub _build_manifest {
102 1     1   10 return Directory::Deploy::Manifest->new();
103             }
104              
105             has maker => qw/is ro lazy_build 1/;
106             sub _build_maker {
107 1     1   2 my $self = shift;
108 1         13 return Directory::Deploy::Maker->new( deploy => $self );
109             }
110              
111             has base => qw/accessor _base required 1/;
112             sub base {
113 4     4 0 5 my $self = shift;
114 4         142 return $self->_base( @_ );
115             }
116              
117             sub BUILD {
118 1     1 0 2596 my $self = shift;
119              
120 1         36 $self->_base( Path::Class::Dir->new( $self->_base ) );
121             }
122              
123             sub file {
124 2     2 0 8 return shift->base->file( @_ );
125             }
126              
127             sub dir {
128 2     2 0 5 return shift->base->subdir( @_ );
129             }
130              
131             sub deploy {
132 1     1 0 8 my $self = shift;
133 1 50       10 if (! ref $self) { # Invoked as a class method
134 0         0 my $new_arguments;
135 0 0       0 $new_arguments = shift if ref $_[0] eq 'HASH';
136 0         0 return $self->new( $new_arguments )->deploy( @_ );
137             }
138              
139             $self->manifest->each( sub {
140 4     4   36 my ($entry) = @_;
141 4         152 $self->maker->make( $entry );
142 1         54 } );
143             }
144              
145             =head1 AUTHOR
146              
147             Robert Krimen, C<< <rkrimen at cpan.org> >>
148              
149             =head1 BUGS
150              
151             Please report any bugs or feature requests to C<bug-directory-deploy at rt.cpan.org>, or through
152             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Directory-Deploy>. I will be notified, and then you'll
153             automatically be notified of progress on your bug as I make changes.
154              
155              
156              
157              
158             =head1 SUPPORT
159              
160             You can find documentation for this module with the perldoc command.
161              
162             perldoc Directory::Deploy
163              
164              
165             You can also look for information at:
166              
167             =over 4
168              
169             =item * RT: CPAN's request tracker
170              
171             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Directory-Deploy>
172              
173             =item * AnnoCPAN: Annotated CPAN documentation
174              
175             L<http://annocpan.org/dist/Directory-Deploy>
176              
177             =item * CPAN Ratings
178              
179             L<http://cpanratings.perl.org/d/Directory-Deploy>
180              
181             =item * Search CPAN
182              
183             L<http://search.cpan.org/dist/Directory-Deploy/>
184              
185             =back
186              
187              
188             =head1 ACKNOWLEDGEMENTS
189              
190              
191             =head1 COPYRIGHT & LICENSE
192              
193             Copyright 2009 Robert Krimen, all rights reserved.
194              
195             This program is free software; you can redistribute it and/or modify it
196             under the same terms as Perl itself.
197              
198              
199             =cut
200              
201             1; # End of Directory::Deploy