| 1 | package Data::AnyBoolean; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | our @ISA = qw(Exporter); | |||||||||
| 8 | 2 | our @EXPORT = qw(anyBool); | |||||||||
| 9 | 2 | our @EXPORT_OK = qw(anyBool); | |||||||||
| 10 | 2 | our %EXPORT_TAGS = (DEFAULT => [qw(anyBool)]); | |||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Data::AnyBoolean - Check none Perl boolean values. | ||||||||||
| 16 | |||||||||||
| 17 | =head1 VERSION | ||||||||||
| 18 | |||||||||||
| 19 | Version 0.0.0 | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 2 | our $VERSION = '0.0.0'; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | use Data::AnyBoolean; | ||||||||||
| 29 | |||||||||||
| 30 | if(anyBool( 'yes' )){ | ||||||||||
| 31 | print 'True' | ||||||||||
| 32 | } | ||||||||||
| 33 | if(anyBool( 'no' )){ | ||||||||||
| 34 | print 'True' | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | Any of the items below are considered false. | ||||||||||
| 38 | |||||||||||
| 39 | undef | ||||||||||
| 40 | /^[Nn][Oo]$/ | ||||||||||
| 41 | /^[Ff][Aa][Ll][Ss][Ee]$/ | ||||||||||
| 42 | /^[Ff]$/ | ||||||||||
| 43 | /^[Oo][Ff][Ff]$/ | ||||||||||
| 44 | |||||||||||
| 45 | Any of the items below are considered true. | ||||||||||
| 46 | |||||||||||
| 47 | /^[Yy][Ee][Ss]$/ | ||||||||||
| 48 | /^[Tt][Rr][Uu][Ee]$/ | ||||||||||
| 49 | /^[Tt]$/ | ||||||||||
| 50 | /^[Oo][Nn]$/ | ||||||||||
| 51 | |||||||||||
| 52 | If any of the above are not matched, it is evaulated as a standard | ||||||||||
| 53 | Perl boolean. | ||||||||||
| 54 | |||||||||||
| 55 | =head1 FUNCTIONS | ||||||||||
| 56 | |||||||||||
| 57 | =head2 anyBool | ||||||||||
| 58 | |||||||||||
| 59 | This returns '0' or '1' after checking the value passed | ||||||||||
| 60 | for the boolean check. | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 0 | ▶ | sub anyBool{ | ||||||||
|
Subroutine
anyBool: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||
| 65 | 0 | my $bool=$_[0]; | |||||||||
| 66 | |||||||||||
| 67 | 0 | ▶ | if (!defined( $bool )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | return 0; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | #yes/no | ||||||||||
| 72 | 0 | ▶ | if ($bool =~/^[Yy][Ee][Ss]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | 0 | return 1; | |||||||||
| 74 | } | ||||||||||
| 75 | 0 | ▶ | if ($bool =~/^[Nn][Oo]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | return 0; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | #true/false | ||||||||||
| 80 | 0 | ▶ | if ($bool =~/^[Tt][Rr][Uu][Ee]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | return 1; | |||||||||
| 82 | } | ||||||||||
| 83 | 0 | ▶ | if ($bool =~/^[Ff][Aa][Ll][Ss][Ee]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | 0 | return 0; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | #on/off | ||||||||||
| 88 | 0 | ▶ | if ($bool =~/^[Oo][Nn]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | 0 | return 1; | |||||||||
| 90 | } | ||||||||||
| 91 | 0 | ▶ | if ($bool =~/^[Oo][Ff][Ff]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | 0 | return 0; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | #t/f | ||||||||||
| 96 | 0 | ▶ | if ($bool =~/^[Tt]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | 0 | return 1; | |||||||||
| 98 | } | ||||||||||
| 99 | 0 | ▶ | if ($bool =~/^[Ff]$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | return 0; | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | #try it the perl way | ||||||||||
| 104 | 0 | ▶ | if ( $bool ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | return 1 | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | return 0; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =head1 AUTHOR | ||||||||||
| 112 | |||||||||||
| 113 | Zane C. Bowers, C<< <vvelox at vvelox.net> >> | ||||||||||
| 114 | |||||||||||
| 115 | =head1 BUGS | ||||||||||
| 116 | |||||||||||
| 117 | Please report any bugs or feature requests to C<bug-data-anybollean at rt.cpan.org>, or through | ||||||||||
| 118 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-AnyBollean>. I will be notified, and then you'll | ||||||||||
| 119 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 120 | |||||||||||
| 121 | |||||||||||
| 122 | |||||||||||
| 123 | |||||||||||
| 124 | =head1 SUPPORT | ||||||||||
| 125 | |||||||||||
| 126 | You can find documentation for this module with the perldoc command. | ||||||||||
| 127 | |||||||||||
| 128 | perldoc Data::AnyBoolean | ||||||||||
| 129 | |||||||||||
| 130 | |||||||||||
| 131 | You can also look for information at: | ||||||||||
| 132 | |||||||||||
| 133 | =over 4 | ||||||||||
| 134 | |||||||||||
| 135 | =item * RT: CPAN's request tracker | ||||||||||
| 136 | |||||||||||
| 137 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Data-AnyBoolean> | ||||||||||
| 138 | |||||||||||
| 139 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 140 | |||||||||||
| 141 | L<http://annocpan.org/dist/Data-AnyBoolean> | ||||||||||
| 142 | |||||||||||
| 143 | =item * CPAN Ratings | ||||||||||
| 144 | |||||||||||
| 145 | L<http://cpanratings.perl.org/d/Data-AnyBoolean> | ||||||||||
| 146 | |||||||||||
| 147 | =item * Search CPAN | ||||||||||
| 148 | |||||||||||
| 149 | L<http://search.cpan.org/dist/Data-AnyBoolean/> | ||||||||||
| 150 | |||||||||||
| 151 | =back | ||||||||||
| 152 | |||||||||||
| 153 | |||||||||||
| 154 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 158 | |||||||||||
| 159 | Copyright 2009 Zane C. Bowers, all rights reserved. | ||||||||||
| 160 | |||||||||||
| 161 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 162 | under the same terms as Perl itself. | ||||||||||
| 163 | |||||||||||
| 164 | |||||||||||
| 165 | =cut | ||||||||||
| 166 | |||||||||||
| 167 | 2 | 1; # End of Data::AnyBoolean | |||||||||