line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scalar::MoreUtils; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
45896
|
use warnings; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
78
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
2
|
|
|
2
|
|
13
|
use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
671
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
11
|
|
|
|
|
|
|
all => [ qw(nil empty define default ifnil ifempty) ], |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
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
|
|
|
15
|
1
|
152
|
sub nil ($) { return ! defined $_[0] } |
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
|
|
100
|
13
|
1
|
299
|
sub empty ($) { return nil $_[0] || 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
|
100
|
|
4
|
1
|
296
|
sub define ($) { return defined $_[0] ? $_[0] : '' } |
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
|
100
|
|
14
|
1
|
827
|
sub default ($$) { return defined $_[0] ? $_[0] : $_[1] } |
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 behaves exactly the same as C. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
*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
|
100
|
|
8
|
1
|
403
|
sub ifempty ($$) { return ! empty $_[0] ? $_[0] : $_[1] } |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=back |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Robert Krimen, C<< >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 BUGS |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
121
|
|
|
|
|
|
|
C, or through the web interface at |
122
|
|
|
|
|
|
|
L. |
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 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * CPAN Ratings |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * Search CPAN |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
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
|
|
|
|
|
|
|
1; # End of Scalar::MoreUtils |