line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Default;
|
2
|
1
|
|
|
1
|
|
14364
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
76
|
|
3
|
1
|
|
|
1
|
|
2459
|
use base 'Exporter';
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
211
|
|
4
|
1
|
|
|
1
|
|
7
|
use vars qw[@ISA @EXPORT_OK %EXPORT_TAGS];
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
95
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# version
|
7
|
1
|
|
|
1
|
|
4
|
use vars '$VERSION';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.11';
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Data::Default -- Small utility for getting the default value of
|
13
|
|
|
|
|
|
|
an argument or variable.
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Data::Default ':all';
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# variables
|
20
|
|
|
|
|
|
|
my ($var);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# later...
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if (default $var, 1) {
|
25
|
|
|
|
|
|
|
# stuff if the $var is undef or set to a true value
|
26
|
|
|
|
|
|
|
}
|
27
|
|
|
|
|
|
|
else {
|
28
|
|
|
|
|
|
|
# stuff if the $var is defined and set to true
|
29
|
|
|
|
|
|
|
}
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Just a little utility for getting the default value of an argument or
|
34
|
|
|
|
|
|
|
parameter. All it really does is accept an array of arguments, then
|
35
|
|
|
|
|
|
|
return the first argument that is defined.
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
This function is usually used in a subroutine to get the
|
38
|
|
|
|
|
|
|
default value of a parameter. A typical usage would be in a subroutine
|
39
|
|
|
|
|
|
|
like this:
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub mysub {
|
42
|
|
|
|
|
|
|
my (%opts) = @_;
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if (default $opts{'some-option'}, 1) {
|
45
|
|
|
|
|
|
|
# do stuff some-option was sent and was true or was not sent
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
else {
|
48
|
|
|
|
|
|
|
# do stuff some-option was sent and was false
|
49
|
|
|
|
|
|
|
}
|
50
|
|
|
|
|
|
|
}
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
You might prefer to use C by Stephen Nelson which
|
53
|
|
|
|
|
|
|
provides similar functionality.
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 INSTALLATION
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
String::Util can be installed with the usual routine:
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
perl Makefile.PL
|
60
|
|
|
|
|
|
|
make
|
61
|
|
|
|
|
|
|
make test
|
62
|
|
|
|
|
|
|
make install
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# export
|
67
|
|
|
|
|
|
|
@ISA = 'Exporter';
|
68
|
|
|
|
|
|
|
@EXPORT_OK = qw[ default defcontent modcontent choose ];
|
69
|
|
|
|
|
|
|
%EXPORT_TAGS = ('all' => [@EXPORT_OK]);
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# default
|
72
|
|
|
|
|
|
|
sub default {
|
73
|
1
|
|
|
1
|
0
|
11
|
for (my $i=0; $i<=$#_; $i++) {
|
74
|
2
|
100
|
|
|
|
10
|
defined($_[$i]) and return $_[$i];
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return undef;
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# return true
|
81
|
|
|
|
|
|
|
1;
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 TERMS AND CONDITIONS
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Copyright (c) 2010 by Miko O'Sullivan. All rights reserved. This program is
|
86
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same terms
|
87
|
|
|
|
|
|
|
as Perl itself. This software comes with B of any kind.
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHORS
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Miko O'Sullivan
|
92
|
|
|
|
|
|
|
F
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=over
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item Version 0.10 November 7, 2010
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Initial release
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item Version 0.11 November 8, 2010
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Fixed bug: Exporter was not being loaded.
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=back
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut
|