| 1 | package Scalar::MoreUtils; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | require Exporter; | |||||||||||||||||||
| 7 | 3 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 3 | @ISA = qw(Exporter); | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | %EXPORT_TAGS = ( | |||||||||||||||||||
| 11 | all => [ qw(nil empty define default ifnil ifempty) ], | ||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Scalar::MoreUtils - Provide the stuff missing in Scalar::Util | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 VERSION | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | Version 0.02 | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | use Scalar::MoreUtils qw(nil empty define default ifnil ifempty); | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | ... | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | sub add { | ||||||||||||||||||||
| 35 | my $left = default shift, 0; | ||||||||||||||||||||
| 36 | my $right = default shift, 0; | ||||||||||||||||||||
| 37 | return $left + $right; | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | sub greet { | ||||||||||||||||||||
| 41 | return default shift, "This the default greeting!"; | ||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | =head1 DESCRIPTION | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | Similar to C<< Hsah::MoreUtils >> and C<< List::MoreUtils >>, C<< Scalar::MoreUtils >> | ||||||||||||||||||||
| 47 | contains trivial but commonly-used scalar functionality. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | Essentially, provide some pretty trivial functionality that I find useful over | ||||||||||||||||||||
| 50 | and over. The value of this module will probably be blasted away by Perl 5.10. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | Suggestions welcome. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =over 4 | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =item nil VALUE | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Returns true if VALUE is not defined. | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =cut | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 15 | ▶ | sub nil ($) { return ! defined $_[0] } | ||||||||||||||||||
|
Subroutine
nil: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =item empty VALUE | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | Returns true if VALUE is not defined or if VALUE is the empty string (""). | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 13 | ▶ | sub empty ($) { return nil $_[0] || 0 == length $_[0] } | ||||||||||||||||||
|
Subroutine
empty: called CC=2 SCAR=6.9
Pod
documented
Condition100%3/3
&nil($_[0]) || 0 == length $_[0]
MC/DC100%2/2
&nil($_[0]) || 0 == length $_[0]
&nil($_[0])
0 == length $_[0]
Truth table100%3/3
A || B
A= &nil($_[0])B= 0 == length $_[0]
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =item define VALUE | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Returns VALUE if it is defined, otherwise returns the empty string (""). | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 4 | ▶ | sub define ($) { return defined $_[0] ? $_[0] : '' } | ||||||||||||||||||
|
Subroutine
define: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =item default VALUE DEFAULT | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Returns VALUE if it is defined, otherwise returns DEFAULT. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | This is similar to the "//" in the Perl 5.10 ... well, not really, but kinda. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 14 | ▶ | sub default ($$) { return defined $_[0] ? $_[0] : $_[1] } | ||||||||||||||||||
|
Subroutine
default: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =item ifnil VALUE DEFAULT | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | Returns VALUE if it is not nil, otherwise returns DEFAULT. | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Read "ifnil(A,B)" as "ifnil A, then B, otherwise A" | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | C<ifnil> behaves exactly the same as C<default>. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 3 | *ifnil = \&default; | |||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =item ifempty VALUE DEFAULT | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | Returns VALUE if it is not empty, otherwise returns DEFAULT. | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Read "ifempty(A,B)" as "ifempty A, then B, otherwise A" | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 8 | ▶ | sub ifempty ($$) { return ! empty $_[0] ? $_[0] : $_[1] } | ||||||||||||||||||
|
Subroutine
ifempty: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =back | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | Robert Krimen, C<< <rkrimen at cpan.org> >> | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head1 BUGS | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Please report any bugs or feature requests to | ||||||||||||||||||||
| 121 | C<bug-scalar-moreutils at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||
| 122 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Scalar-MoreUtils>. | ||||||||||||||||||||
| 123 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||
| 124 | your bug as I make changes. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 SUPPORT | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | perldoc Scalar::MoreUtils | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | You can also look for information at: | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =over 4 | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | L<http://annocpan.org/dist/Scalar-MoreUtils> | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =item * CPAN Ratings | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | L<http://cpanratings.perl.org/d/Scalar-MoreUtils> | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =item * RT: CPAN's request tracker | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Scalar-MoreUtils> | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =item * Search CPAN | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | L<http://search.cpan.org/dist/Scalar-MoreUtils> | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =back | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | Copyright 2007 Robert Krimen, all rights reserved. | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 161 | under the same terms as Perl itself. | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | 3 | 1; # End of Scalar::MoreUtils | |||||||||||||||||||