File Coverage

blib/lib/CPAN/Reporter/Smoker/OpenBSD.pm
Criterion Covered Total %
statement 33 37 89.1
branch 5 8 62.5
condition 1 2 50.0
subroutine 7 7 100.0
pod 2 2 100.0
total 48 56 85.7


line stmt bran cond sub pod time code
1             package CPAN::Reporter::Smoker::OpenBSD;
2 2     2   119953 use warnings;
  2         13  
  2         55  
3 2     2   10 use strict;
  2         2  
  2         36  
4 2     2   7 use Exporter 'import';
  2         3  
  2         73  
5 2     2   2648 use CPAN;
  2         510757  
  2         916  
6 2     2   50 use CPAN::HandleConfig;
  2         12  
  2         1081  
7              
8             our @EXPORT_OK = qw(is_distro_ok block_distro);
9              
10             our $VERSION = '0.019'; # VERSION
11              
12             =pod
13              
14             =head1 NAME
15              
16             CPAN::Reporter::Smoker::OpenBSD - set of scripts to manage a
17             L on OpenBSD
18              
19             =head1 DESCRIPTION
20              
21             This module exports some functions used to manage a smoker testing machine based L.
22              
23             =head1 EXPORTS
24              
25             Only the C C is exported, if explicit requested.
26              
27             =head2 is_distro_ok
28              
29             Expects as parameter a string in the format /.
30              
31             It executes some very basic testing against the string.
32              
33             Returns true or false depending if the string passes the tests. It will also C if things are not going OK.
34              
35             =cut
36              
37             sub is_distro_ok {
38 151     151 1 35628 my $distro = shift;
39              
40 151 50       295 unless ( defined($distro) ) {
41 0         0 warn "--distro is a required parameter!\n\n";
42 0         0 return 0;
43             }
44              
45 151 100       780 unless ( $distro =~ /^\w+\/[\w-]+$/ ) {
46 1         12 warn "invalid string '$distro' in --distro!\n\n";
47 1         7 return 0;
48             }
49             else {
50 150         493 return 1;
51             }
52             }
53              
54             =head2 block_distro
55              
56             Blocks a distribution to be tested under the smoker by using a distroprefs file.
57              
58             Expects as parameters:
59              
60             =over
61              
62             =item 1.
63              
64             a distribution name (for example, "JOHNDOE/Some-Distro-Name").
65              
66             =item 2.
67              
68             The perl interpreter (which is in execution) configuration.
69              
70             =item 3.
71              
72             An comment to include in the distroprefs file.
73              
74             =back
75              
76             It returns a hash reference containing keys/values that could be directly
77             serialized to YAML (or other format) but the C key, that contains
78             a suggest complete path to the distroprefs file (based on the L C configuration
79             client.
80              
81             If there is an already file created as defined in C key, it will C and return C.
82              
83             =cut
84              
85             sub block_distro {
86 2     2 1 440 my ( $distro, $perl_info, $comment ) = @_;
87 2         7 my $distribution = '^' . $distro;
88 2         5 my $filename = "$distro.yml";
89 2         27 $filename =~ s/\//./;
90              
91 2   50     16 my %data = (
92             comment => $comment || 'Tests hang smoker',
93             match => {
94             distribution => $distribution,
95             perlconfig => $perl_info
96             },
97             disabled => 1
98             );
99              
100 2         10 CPAN::HandleConfig->load;
101 2         130 my $prefs_dir = $CPAN::Config->{prefs_dir};
102 2 50       31 die "$prefs_dir does not exist or it is not readable\n"
103             unless ( -d $prefs_dir );
104 2         25 my $full_path = File::Spec->catfile( $prefs_dir, $filename );
105              
106 2 50       41 if ( -f $full_path ) {
107 0         0 warn "$full_path already exists, will not overwrite it.";
108 0         0 return;
109             }
110             else {
111 2         7 $data{full_path} = $full_path;
112 2         10 return \%data;
113             }
114             }
115              
116             =head1 SEE ALSO
117              
118             For more details about those programs interact with the smoker and L, be sure
119             to read the documentation about L client, especially the part about DistroPrefs.
120              
121             You will also want to take a look at the following programs documentation:
122              
123             =over
124              
125             =item *
126              
127             C
128              
129             =item *
130              
131             C
132              
133             =item *
134              
135             C
136              
137             =back
138              
139             =head1 AUTHOR
140              
141             Alceu Rodrigues de Freitas Junior, Earfreitas@cpan.orgE
142              
143             =head1 COPYRIGHT AND LICENSE
144              
145             This software is copyright (c) 2017 of Alceu Rodrigues de Freitas Junior, arfreitas@cpan.org
146              
147             This file is part of CPAN OpenBSD Smoker.
148              
149             CPAN OpenBSD Smoker is free software: you can redistribute it and/or modify
150             it under the terms of the GNU General Public License as published by
151             the Free Software Foundation, either version 3 of the License, or
152             (at your option) any later version.
153              
154             CPAN OpenBSD Smoker is distributed in the hope that it will be useful,
155             but WITHOUT ANY WARRANTY; without even the implied warranty of
156             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
157             GNU General Public License for more details.
158              
159             You should have received a copy of the GNU General Public License
160             along with CPAN OpenBSD Smoker. If not, see .
161              
162             =cut
163              
164             1;