| 1 | package Test::Smoke::App::AppOptionCollection; | ||||||||||||||||||||
| 2 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 11 | our $VERSION = '0.001'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 11 | ▶ | use base 'Test::Smoke::ObjectBase'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | Test::Smoke::App::AppOptionCollection - A collection of AppOption objects. | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head2 Test::Smoke::App::AppOptionCollection->new() | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head3 Arguments | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | An optional list of L<Test::Smoke::App::AppOption> objects. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head3 Returns | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | An instatiated object. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head3 Exceptions | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | None. | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 30 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 32 | 30 | my $class = shift; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 30 | my $struct = { | |||||||||||||||||||
| 35 | _added_options => [], | ||||||||||||||||||||
| 36 | _options_hash => {}, | ||||||||||||||||||||
| 37 | _options_list => [], | ||||||||||||||||||||
| 38 | _helptext => '', | ||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 30 | my $self = bless $struct, $class; | |||||||||||||||||||
| 42 | 30 | $self->add(@_); | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 30 | return $self; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =head2 $collection->add(@arguments) | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Add the L<Getopt::Long> option and default to the collection. Also add the | ||||||||||||||||||||
| 50 | L<Test::Smoke::App::AppOption->show_helptext()> to the running helptext variable. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =head3 Arguments | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | A list of L<Test::Smoke::AppOption> objects. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head3 Returns | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | The object. | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head3 Exceptions | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | None. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 731 | ▶ | sub add { | ||||||||||||||||||
|
Subroutine
add: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 67 | 731 | my $self = shift; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 731 | for my $tsao (@_) { | |||||||||||||||||||
| 70 | 701 | push @{$self->added_options}, $tsao; | |||||||||||||||||||
| 71 | 701 | $self->options_hash->{$tsao->name} = $tsao->default; | |||||||||||||||||||
| 72 | 640 | push @{ $self->options_list }, $tsao->gol_option | |||||||||||||||||||
| 73 | 701 | ▶ | if !grep $_ eq $tsao->gol_option, @{$self->options_list}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 701 | ▶ | $self->add_helptext($tsao->show_helptext) if $tsao->helptext; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 731 | return $self; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head2 $collection->add_helptext($string) | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Adds a string to the currently build up helptext variable. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 800 | ▶ | sub add_helptext { | ||||||||||||||||||
|
Subroutine
add_helptext: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 87 | 800 | my $self = shift; | |||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 800 | $self->{_helptext} .= shift; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head2 $collection->options_with_default() | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head3 Arguments | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | None | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head3 Returns | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | A hasref to a struct with only the defaults set from object construction. | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 29 | ▶ | sub options_with_default { | ||||||||||||||||||
|
Subroutine
options_with_default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 105 | 29 | my $self = shift; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | my %defaults = map { | ||||||||||||||||||||
| 108 | 592 | +($_->name => $_->default) | |||||||||||||||||||
| 109 | } grep | ||||||||||||||||||||
| 110 | $_->had_default | ||||||||||||||||||||
| 111 | 29 | , @{$self->added_options}; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 29 | return \%defaults; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =head2 $collection->options_for_cli() | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head3 Arguments | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | None | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head3 Returns | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | A hashref with options that have a CODEref as default. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head3 Exceptions | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | None | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 29 | ▶ | sub options_for_cli { | ||||||||||||||||||
|
Subroutine
options_for_cli: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 133 | 29 | my $self = shift; | |||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | my %clis = map { | ||||||||||||||||||||
| 136 | 29 | ▶ | +($_->name => $_->default) | ||||||||||||||||||
|
Condition100%3/3
$_->had_default && ref $_->default eq 'CODE'
MC/DC100%2/2
$_->had_default && ref $_->default eq 'CODE'
$_->had_default
ref $_->default eq 'CODE'
Truth table100%3/3
A && B
A= $_->had_defaultB= ref $_->default eq 'CODE'
| |||||||||||||||||||||
| 137 | } grep | ||||||||||||||||||||
| 138 | $_->had_default && ref($_->default) eq 'CODE' | ||||||||||||||||||||
| 139 | 29 | , @{$self->added_options}; | |||||||||||||||||||
| 140 | 29 | return \%clis; | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =head2 $collection->all_options() | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =head3 Arguments | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | None. | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =head3 Returns | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | A hashref with all options and theire coded default. | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head3 Exceptions | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | None. | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | 29 | ▶ | sub all_options { | ||||||||||||||||||
|
Subroutine
all_options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 160 | 29 | my $self = shift; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | return { | ||||||||||||||||||||
| 163 | map { | ||||||||||||||||||||
| 164 | 699 | +($_->name => $_->default) | |||||||||||||||||||
| 165 | 29 | } @{$self->added_options} | |||||||||||||||||||
| 166 | }; | ||||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 11 | 1; | |||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =head1 COPYRIGHT | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | (c) 2002-2013, Abe Timmerman <abeltje@cpan.org> All rights reserved. | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | With contributions from Jarkko Hietaniemi, Merijn Brand, Campo | ||||||||||||||||||||
| 176 | Weijerman, Alan Burlison, Allen Smith, Alain Barbet, Dominic Dunlop, | ||||||||||||||||||||
| 177 | Rich Rauenzahn, David Cantrell. | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 180 | it under the same terms as Perl itself. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | See: | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =over 4 | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | =item * L<http://www.perl.com/perl/misc/Artistic.html> | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =item * L<http://www.gnu.org/copyleft/gpl.html> | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =back | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 193 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 194 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||