File Coverage

blib/lib/App/Sky/Module.pm
Criterion Covered Total %
statement 43 45 95.5
branch 7 10 70.0
condition 2 2 100.0
subroutine 11 11 100.0
pod 1 1 100.0
total 64 69 92.7


line stmt bran cond sub pod time code
1             package App::Sky::Module;
2             $App::Sky::Module::VERSION = '0.4.2';
3 2     2   77700 use strict;
  2         13  
  2         58  
4 2     2   10 use warnings;
  2         4  
  2         52  
5              
6              
7 2     2   40 use Carp ();
  2         4  
  2         51  
8              
9 2     2   472 use Moo;
  2         8478  
  2         11  
10 2     2   2073 use MooX 'late';
  2         9194  
  2         14  
11              
12 2     2   130641 use URI;
  2         4030  
  2         66  
13 2     2   13 use File::Basename qw(basename);
  2         5  
  2         132  
14              
15 2     2   1124 use List::MoreUtils qw( uniq );
  2         16735  
  2         16  
16              
17 2     2   2880 use App::Sky::Results;
  2         7  
  2         77  
18 2     2   860 use App::Sky::Exception;
  2         7  
  2         620  
19              
20             has base_upload_cmd => ( isa => 'ArrayRef[Str]', is => 'ro', );
21             has dest_upload_prefix => ( isa => 'Str', is => 'ro', );
22             has dest_upload_url_prefix => ( isa => 'Str', is => 'ro', );
23              
24              
25             sub get_upload_results
26             {
27 11     11 1 18961 my ( $self, $args ) = @_;
28              
29 11   100     49 my $is_dir = ( $args->{is_dir} // 0 );
30              
31             my $filenames = $args->{filenames}
32 11 50       33 or Carp::confess("Missing argument 'filenames'");
33              
34 11 50       26 if ( @$filenames != 1 )
35             {
36 0         0 Carp::confess("More than one file passed to 'filenames'");
37             }
38              
39             my $target_dir = $args->{target_dir}
40 11 50       26 or Carp::confess("Missing argument 'target_dir'");
41              
42 11         44 my $invalid_chars_re = qr/[:]/;
43              
44             my @invalid_chars =
45 11         22 ( map { split( //, $_ ) } map { /($invalid_chars_re)/g } @$filenames );
  1         4  
  11         89  
46              
47 11 100       27 if (@invalid_chars)
48             {
49             App::Sky::Exception::Upload::Filename::InvalidChars->throw(
50 1         23 invalid_chars => [ sort { $a cmp $b } uniq(@invalid_chars) ], );
  0         0  
51             }
52              
53             return App::Sky::Results->new(
54             {
55             upload_cmd => [
56 10 100       17 @{ $self->base_upload_cmd() },
  10         395  
57             @$filenames,
58             ( $self->dest_upload_prefix() . $target_dir ),
59             ],
60             urls => [
61             URI->new(
62             $self->dest_upload_url_prefix()
63             . $target_dir
64             . basename( $filenames->[0] )
65             . ( $is_dir ? '/' : '' )
66             ),
67             ],
68             }
69             );
70             }
71              
72             1;
73              
74             __END__
75              
76             =pod
77              
78             =encoding UTF-8
79              
80             =head1 NAME
81              
82             App::Sky::Module - class that does the heavy lifting.
83              
84             =head1 VERSION
85              
86             version 0.4.2
87              
88             =head1 METHODS
89              
90             =head2 $sky->base_upload_cmd()
91              
92             Returns an array reference of strings of the upload command.
93              
94             =head2 $sky->dest_upload_prefix
95              
96             The upload prefix to upload to. So:
97              
98             my $m = App::Sky::Module->new(
99             {
100             base_upload_cmd => [qw(rsync -a -v --progress --inplace)],
101             dest_upload_prefix => 'hostgator:public_html/',
102             dest_upload_url_prefix => 'http://www.shlomifish.org/',
103             }
104             );
105              
106             =head2 $sky->dest_upload_url_prefix
107              
108             The base URL where the uploads will be found.
109              
110             =head2 my $results = $sky->get_upload_results({ filenames => ["Shine4U.webm"], target_dir => "Files/files/video/" });
111              
112             Gives the recipe to execute for the upload commands.
113              
114             Returns a L<App::Sky::Results> reference containing:
115              
116             =over 4
117              
118             =item * upload_cmd
119              
120             The upload command to execute (as an array reference of strings).
121              
122             =back
123              
124             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
125              
126             =head1 SUPPORT
127              
128             =head2 Websites
129              
130             The following websites have more information about this module, and may be of help to you. As always,
131             in addition to those websites please use your favorite search engine to discover more resources.
132              
133             =over 4
134              
135             =item *
136              
137             MetaCPAN
138              
139             A modern, open-source CPAN search engine, useful to view POD in HTML format.
140              
141             L<https://metacpan.org/release/App-Sky>
142              
143             =item *
144              
145             RT: CPAN's Bug Tracker
146              
147             The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
148              
149             L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-Sky>
150              
151             =item *
152              
153             CPANTS
154              
155             The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
156              
157             L<http://cpants.cpanauthors.org/dist/App-Sky>
158              
159             =item *
160              
161             CPAN Testers
162              
163             The CPAN Testers is a network of smoke testers who run automated tests on uploaded CPAN distributions.
164              
165             L<http://www.cpantesters.org/distro/A/App-Sky>
166              
167             =item *
168              
169             CPAN Testers Matrix
170              
171             The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.
172              
173             L<http://matrix.cpantesters.org/?dist=App-Sky>
174              
175             =item *
176              
177             CPAN Testers Dependencies
178              
179             The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
180              
181             L<http://deps.cpantesters.org/?module=App::Sky>
182              
183             =back
184              
185             =head2 Bugs / Feature Requests
186              
187             Please report any bugs or feature requests by email to C<bug-app-sky at rt.cpan.org>, or through
188             the web interface at L<https://rt.cpan.org/Public/Bug/Report.html?Queue=App-Sky>. You will be automatically notified of any
189             progress on the request by the system.
190              
191             =head2 Source Code
192              
193             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
194             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
195             from your repository :)
196              
197             L<https://github.com/shlomif/Sky-uploader>
198              
199             git clone git://github.com/shlomif/Sky-uploader.git
200              
201             =head1 AUTHOR
202              
203             Shlomi Fish <shlomif@cpan.org>
204              
205             =head1 BUGS
206              
207             Please report any bugs or feature requests on the bugtracker website
208             L<https://github.com/shlomif/Sky-uploader/issues>
209              
210             When submitting a bug or request, please include a test-file or a
211             patch to an existing test-file that illustrates the bug or desired
212             feature.
213              
214             =head1 COPYRIGHT AND LICENSE
215              
216             This software is Copyright (c) 2013 by Shlomi Fish.
217              
218             This is free software, licensed under:
219              
220             The MIT (X11) License
221              
222             =cut