blib/lib/Test/Smoke/Syncer.pm

filter: Statementstmt 93.1% 81 / 87 Branchbran 80.0% 16 / 20 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 15 / 15 Podpod 100% 2 / 2 totaltotal 88.6% 117 / 132 CC 13 SCAR 16.8
CC
13
Cov
89%
new
10.0
config
7.9
BEGIN
1.0
CRAP 5.4
« blib/lib/Test/Smoke/Poster/Curl.pm ↑ Summary blib/lib/Test/Smoke/App/Base.pm »
1 package Test::Smoke::Syncer;
2 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 ▶use Test::Smoke::Syncer::Rsync;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Test::Smoke::Syncer::Git;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Test::Smoke::Syncer::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Test::Smoke::Syncer::Hardlink;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Test::Smoke::Syncer::Snapshot;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Test::Smoke::Syncer::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Test::Smoke::Syncer::Forest;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $VERSION = '0.029';
15  
16 12 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use Cwd qw( cwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 require File::Path;
20  
21 my %CONFIG = (
22 df_sync => 'rsync',
23 df_ddir => File::Spec->rel2abs( 'perl-current', abs_path() ),
24 df_v => 0,
25  
26 # these settings have to do synctype==rsync
27 df_rsync => 'rsync', # you might want a path there
28 df_opts => '-az --delete',
29 df_source => 'github.com/Perl::perl-current',
30  
31 rsync => {
32 allowed => [qw(rsync source opts)],
33 required => [qw(rsync source)],
34 class => 'Test::Smoke::Syncer::Rsync',
35 },
36  
37 # these settings have to do with synctype==copy
38 df_cdir => undef,
39  
40 copy => {
41 allowed => [qw(cdir)],
42 required => [qw(cdir)],
43 class => 'Test::Smoke::Syncer::Copy',
44 },
45  
46 # these settings have to do with synctype==hardlink
47 df_hdir => undef,
48 12 ▶ df_haslink => ($Config{d_link}||'') eq 'define',
Condition50%1/2
$Test::Smoke::Syncer::Config{'d_link'} || ''
l!l
120
MC/DC0%0/1
$Test::Smoke::Syncer::Config{'d_link'} || ''
$Test::Smoke::Syncer::Config{'d_link'}
Truth table50%1/2
A
A= $Test::Smoke::Syncer::Config{'d_link'}
Aresult
11
00
49  
50 hardlink => {
51 allowed => [qw( hdir haslink )],
52 required => [qw(hdir)],
53 class => 'Test::Smoke::Syncer::Hardlink',
54 },
55  
56 # these have to do 'forest'
57 df_fsync => 'rsync',
58 df_mdir => undef,
59 df_fdir => undef,
60  
61 forest => {
62 allowed => [qw(fsync mdir fdir)],
63 required => [qw(mdir fdir)],
64 class => 'Test::Smoke::Syncer::Forest',
65 },
66  
67 # these settings have to do with synctype==ftp
68 df_ftphost => 'ftp.example.com',
69 df_ftpport => 21,
70 df_ftpsdir => '/',
71 df_ftype => undef,
72  
73 ftp => {
74 allowed => [qw(ftphost ftpport ftpusr ftppwd ftpsdir ftype)],
75 required => [qw()],
76 class => 'Test::Smoke::Syncer::FTP',
77 },
78  
79 # these settings have to do with synctype==snapshot
80 df_snapurl => 'https://github.com/Perl/perl5/archive/refs/heads/blead.tar.gz',
81 df_snaptar => '',
82  
83 snapshot => {
84 allowed => [qw(snapurl snaptar)],
85 required => [qw()],
86 class => 'Test::Smoke::Syncer::Snapshot',
87 },
88  
89 # synctype: git
90 df_gitbin => 'git',
91 df_gitorigin => 'https://github.com/Perl/perl5.git',
92 df_gitdir => undef,
93 df_gitbare => 0,
94 df_gitdfbranch => 'blead',
95 df_gitbranchfile => undef,
96  
97 git => {
98 allowed => [qw(gitbin gitorigin gitdir gitbare gitdfbranch gitbranchfile)],
99 required => [qw(gitbin gitorigin gitdir)],
100 class => 'Test::Smoke::Syncer::Git',
101 },
102  
103 # misc.
104 valid_type => { rsync => 1, git => 1, snapshot => 1,
105 copy => 1, hardlink => 1, ftp => 1 },
106 );
107  
108 {
109 12 my %allkeys = map {
110 240 ($_ => 1)
111 } map
112 72 @{ $CONFIG{ $_ }{allowed} }
113 12 , keys %{ $CONFIG{valid_type} };
114  
115 12 push @{ $CONFIG{forest}{allowed} }, keys %allkeys;
116 12 $CONFIG{forest}{required} = [];
117 12 $CONFIG{forest}{class} = 'Test::Smoke::Syncer::Forest';
118 12 $CONFIG{valid_type}->{forest} = 1;
119 }
120  
121 =head1 NAME
122  
123 Test::Smoke::Syncer - Factory for syncer objects.
124  
125 =head1 SYNOPSIS
126  
127 use Test::Smoke::Syncer;
128  
129 my $type = 'rsync'; # or 'snapshot' or 'copy'
130 my $syncer = Test::Smoke::Syncer->new( $type => \%sync_config );
131 my $patch_level = $syncer->sync;
132  
133 =head1 DESCRIPTION
134  
135 At this moment we support three basic types of syncing the perl source-tree.
136  
137 =over
138  
139 =item rsync
140  
141 This method uses the B<rsync> program with the C<< --delete >> option
142 to get your perl source-tree up to date.
143  
144 =item snapshot
145  
146 This method uses the B<Net::FTP> or the B<LWP> module to get the
147 latest snapshot. When the B<server> attribute starts with I<http://>
148 the fetching is done by C<LWP::Simple::mirror()>.
149 To emulate the C<< rsync --delete >> effect, the current source-tree
150 is removed.
151  
152 The snapshot tarball is handled by either B<tar>/B<gzip> or
153 B<Archive::Tar>/B<Compress::Zlib>.
154  
155 =item copy
156  
157 This method uses the B<File::Copy> module to copy an existing source-tree
158 from somewhere on the system (in case rsync doesn't work), this also
159 removes the current source-tree first.
160  
161 =item forest
162  
163 This method will sync the source-tree in one of the above basic methods.
164 After that, it will create an intermediate copy of the master directory
165 as hardlinks and run the F<regen_headers.pl> script. This should yield
166 an up-to-date source-tree. The intermediate directory is now copied as
167 hardlinks to its final directory ({ddir}).
168  
169 This can be used to change the way B<make distclean> is run from
170 F<mktest.pl> (removes all files that are not in the intermediate
171 directory, which may prove faster than traditional B<make distclean>).
172  
173 =back
174  
175 =head1 METHODS
176  
177 =head2 Test::Smoke::Syncer->new( $type, \%sync_config )
178  
179 [ Constructor | Public ]
180  
181 Initialise a new object and check all relevant arguments.
182 It returns an object of the appropriate B<Test::Smoke::Syncer::*> class.
183  
184 =cut
185  
186 20 ▶sub new {
Subroutine new: called CC=10 SCAR=23.0
Pod documented
187 20 my $factory = shift;
188  
189 20 ▶ my $sync_type = lc(shift || $CONFIG{df_sync});
Condition66%2/3
shift() || $CONFIG{'df_sync'}
l!l&&r!l&&!r
1910
MC/DC0%0/2
shift() || $CONFIG{'df_sync'}
shift() $CONFIG{'df_sync'}
Truth table66%2/3
A || B
A= shift()B= $CONFIG{'df_sync'}
ABresult
1X1
011
000
190  
191 20 ▶ if ( !exists $CONFIG{valid_type}{$sync_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $CONFIG{"valid_type"}{$sync_type}) 1 19 20
192 1 croak( "Invalid sync_type '$sync_type'" );
193 };
194  
195 19 ▶ my %args_raw = @_ ? UNIVERSAL::isa( $_[0], 'HASH' ) ? %{ $_[0] } : @_ : ();
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 18 1 19
UNIVERSAL::isa($_[0], 'HASH') ? : 13 5 18
196  
197 my %args = map {
198 19 ( my $key = $_ ) =~ s/^-?(.+)$/lc $1/e;
199 87 ( $key => $args_raw{ $_ } );
200 } keys %args_raw;
201  
202 my %fields = map {
203 92 ▶ my $value = exists $args{$_} ? $args{ $_ } : $CONFIG{ "df_$_" };
Branch: 1 branch
BranchTrueFalseTotal
exists $args{$_} ? : 62 30 92
204 92 ( $_ => $value )
205 19 } ( v => ddir => @{ $CONFIG{$sync_type}{allowed} } );
206 19 ▶ if ( ! File::Spec->file_name_is_absolute( $fields{ddir} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($fields{"ddir"})) 5 14 19
207 5 $fields{ddir} = File::Spec->catdir( abs_path(), $fields{ddir} );
208 }
209 19 $fields{ddir} = File::Spec->rel2abs( $fields{ddir}, abs_path() );
210  
211 19 my @missing;
212 19 for my $required (@{ $CONFIG{$sync_type}{required} }) {
213 push(
214 @missing,
215 "option '$required' missing for '$CONFIG{$sync_type}{class}'"
216 22 ▶ ) if !defined $fields{$required};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields{$required} 1 21 22
217 }
218 19 ▶ if (@missing) {
Branch: 1 branch
BranchTrueFalseTotal
if (@missing) 1 18 19
219 1 croak("Missing option:\n\t", join("\n\t", @missing));
220 }
221  
222 18 my $class = $CONFIG{$sync_type}{class};
223 18 return $class->new(%fields);
224 }
225  
226 =head2 Test::Smoke::Syncer->config( $key[, $value] )
227  
228 [ Accessor | Public ]
229  
230 C<config()> is an interface to the package lexical C<%CONFIG>,
231 which holds all the default values for the C<new()> arguments.
232  
233 With the special key B<all_defaults> this returns a reference
234 to a hash holding all the default values.
235  
236 =cut
237  
238 1 ▶sub config {
Subroutine config: called CC=4 SCAR=20.7
Pod documented
239 1 my $dummy = shift;
240  
241 1 my $key = lc shift;
242  
243 1 ▶ if ( $key eq 'all_defaults' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "all_defaults") 0 1 1
244 my %default = map {
245 0 my( $pass_key ) = $_ =~ /^df_(.+)/;
246 0 ( $pass_key => $CONFIG{ $_ } );
247 } grep /^df_/ => keys %CONFIG;
248 0 return \%default;
249 }
250  
251 1 ▶ return undef unless exists $CONFIG{ "df_$key" };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CONFIG{"df_$key"} 1 0 1
252  
253 0 ▶ $CONFIG{ "df_$key" } = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
254  
255 0 return $CONFIG{ "df_$key" };
256 }
257  
258 =head1 SEE ALSO
259  
260 L<rsync>, L<gzip>, L<tar>, L<Archive::Tar>, L<Compress::Zlib>,
261 L<File::Copy>, L<Test::Smoke::SourceTree>
262  
263 =head1 COPYRIGHT
264  
265 (c) 2002-2013, All rights reserved.
266  
267 * Abe Timmerman <abeltje@cpan.org>
268  
269 This library is free software; you can redistribute it and/or modify
270 it under the same terms as Perl itself.
271  
272 See:
273  
274 * <http://www.perl.com/perl/misc/Artistic.html>,
275 * <http://www.gnu.org/copyleft/gpl.html>
276  
277 This program is distributed in the hope that it will be useful,
278 but WITHOUT ANY WARRANTY; without even the implied warranty of
279 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
280  
281 =cut
« blib/lib/Test/Smoke/Poster/Curl.pm ↑ Summary blib/lib/Test/Smoke/App/Base.pm »