Devel-CoverReport
view release on metacpan or search on metacpan
lib/Devel/CoverReport/App/CoverReport.pm view on Meta::CPAN
sub cover_run_options { # {{{
my %raw_options = @_;
if (not $raw_options{'cover_db'}) {
$raw_options{'cover_db'} = 'cover_db';
}
if (not $raw_options{'output'}) {
$raw_options{'output'} = $raw_options{'cover_db'};
}
if (not $raw_options{'formatter'}) {
$raw_options{'formatter'} = 'Html';
}
my %run_options = (
'cover_db' => $raw_options{'cover_db'},
'formatter' => $raw_options{'formatter'},
'output' => $raw_options{'output'},
'jobs' => $raw_options{'jobs'},
);
# Work out trigger options:
foreach my $option (qw( verbose quiet summary )) {
if ($raw_options{$option}) {
$run_options{$option} = 1;
}
else {
$run_options{$option} = 0;
}
}
# Handle 'all/none/selected'-type of options.
my %allowed_selections = (
criterion => {
'statement' => 1,
'branch' => 1,
'condition' => 1,
'path' => 1,
'subroutine' => 1,
'pod' => 1,
'time' => 1,
},
report => {
'summary' => 1,
'index' => 1,
'coverage' => 1,
'runs' => 1,
'run-details' => 1,
'vcs' => 1,
},
);
foreach my $option (qw( report criterion )) {
# If not specified, we assume: gimme all You got ;)
if (not scalar @{ $raw_options{$option} } ) {
$raw_options{$option} = [ 'all' ];
}
my @strings;
foreach my $string (@{ $raw_options{$option} }) {
push @strings, ( split m{\,[\s]*}s, $string );
}
foreach my $string (@strings) {
if ($string eq 'all') {
foreach my $_string (keys %{ $allowed_selections{$option} }) {
$run_options{$option}->{ $_string } = 2;
}
# There is no much sense in checking other strings...
last;
}
if ($allowed_selections{$option}->{$string}) {
$run_options{$option}->{ $string } = 1;
next;
}
pod2usage("Unsupported value for $option: " . $string);
}
}
# Handle option lists...
my %item_used;
foreach my $option (qw( exclude exclude_dir exclude_re include include_dir include_re mention mention_dir mention_re )) {
if (scalar @{ $raw_options{$option} }) {
$item_used{$option} = 1;
}
$run_options{$option} = $raw_options{$option}
}
# If no selection-related options ware used, set sane defaults.
if (not scalar %item_used) {
# Passing a copy of the array should be safer, right? ;)
$run_options{'mention_dir'} = [ @INC ];
}
# If some options ware used, but 'include' was not defined - we MUST provide some sane default.
# If we do not do it, no file will be selected, which probably is not user expects.
if (not $item_used{'include'} and not $item_used{'include_dir'} and not $item_used{'include_re'}) {
$run_options{'include_re'} = [ '.' ]; # Something, that always matches.
}
return %run_options;
} # }}}
1;
=back
=head1 LICENCE
Copyright 2009-2012, BartÅomiej SyguÅa (perl@bs502.pl)
This is free software. It is licensed, and can be distributed under the same terms as Perl itself.
For more, see my website: http://bs502.pl/
=cut
# vim: fdm=marker
( run in 0.778 second using v1.01-cache-2.11-cpan-71847e10f99 )