| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
152388
|
use 5.008; |
|
|
1
|
|
|
|
|
6
|
|
|
|
1
|
|
|
|
|
64
|
|
|
2
|
1
|
|
|
1
|
|
8
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
56
|
|
|
3
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
88
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Getopt::Attribute; |
|
6
|
|
|
|
|
|
|
BEGIN { |
|
7
|
1
|
|
|
1
|
|
39
|
$Getopt::Attribute::VERSION = '2.101700'; |
|
8
|
|
|
|
|
|
|
} |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Attribute wrapper for Getopt::Long |
|
11
|
1
|
|
|
1
|
|
1804
|
use Getopt::Long; |
|
|
1
|
|
|
|
|
25354
|
|
|
|
1
|
|
|
|
|
7
|
|
|
12
|
1
|
|
|
1
|
|
1212
|
use Attribute::Handlers; |
|
|
1
|
|
|
|
|
6701
|
|
|
|
1
|
|
|
|
|
8
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub UNIVERSAL::Getopt : ATTR(RAWDATA,BEGIN) { |
|
15
|
10
|
|
|
10
|
0
|
11338
|
my ($ref, $data) = @_[ 2, 4 ]; |
|
16
|
10
|
|
|
|
|
14
|
our %options; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# this has to be an array as we're chasing refs later |
|
19
|
10
|
100
|
|
|
|
58
|
if ($data =~ m/^(\S+)\s+(.*)/) { |
|
20
|
2
|
|
|
|
|
7
|
$data = $1; |
|
21
|
2
|
|
|
|
|
6
|
push our @defaults, [ $ref => $2 ]; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
10
|
|
|
|
|
31
|
$options{$data} = $ref; |
|
24
|
1
|
|
|
1
|
|
148
|
} |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
25
|
|
|
|
|
|
|
INIT { |
|
26
|
1
|
|
|
1
|
|
65
|
our $error = 0; |
|
27
|
1
|
50
|
|
|
|
14
|
GetOptions(our %options) or $error = 1; |
|
28
|
1
|
|
100
|
|
|
2282
|
defined ${ $_->[0] } or ${ $_->[0] } = $_->[1] for our @defaults; |
|
|
2
|
|
|
|
|
18
|
|
|
|
1
|
|
|
|
|
4
|
|
|
29
|
|
|
|
|
|
|
} |
|
30
|
0
|
|
|
0
|
1
|
|
sub options { our %options } |
|
31
|
0
|
|
|
0
|
1
|
|
sub error { our $error } |
|
32
|
|
|
|
|
|
|
1; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
|
36
|
|
|
|
|
|
|
=pod |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Getopt::Attribute - Attribute wrapper for Getopt::Long |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 VERSION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
version 2.101700 |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use Getopt::Attribute; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our $verbose : Getopt(verbose!); |
|
51
|
|
|
|
|
|
|
our $all : Getopt(all); |
|
52
|
|
|
|
|
|
|
our $size : Getopt(size=s); |
|
53
|
|
|
|
|
|
|
our $more : Getopt(more+); |
|
54
|
|
|
|
|
|
|
our @library : Getopt(library=s); |
|
55
|
|
|
|
|
|
|
our %defines : Getopt(define=s); |
|
56
|
|
|
|
|
|
|
sub quiet : Getopt(quiet) { our $quiet_msg = 'seen quiet' } |
|
57
|
|
|
|
|
|
|
usage() if our $man : Getopt(man); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Meanwhile, on some command line: |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# mypgm.pl --noverbose --all --size=23 --more --more --more --quiet |
|
62
|
|
|
|
|
|
|
# --library lib/stdlib --library lib/extlib |
|
63
|
|
|
|
|
|
|
# --define os=linux --define vendor=redhat --man -- foo |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Note: This version of the module works works with perl 5.8.0. If you |
|
68
|
|
|
|
|
|
|
need it to work with perl 5.6.x, please use an earlier version from CPAN. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This module provides an attribute wrapper around C<Getopt::Long>. |
|
71
|
|
|
|
|
|
|
Instead of declaring the options in a hash with references to the |
|
72
|
|
|
|
|
|
|
variables and subroutines affected by the options, you can use the |
|
73
|
|
|
|
|
|
|
C<Getopt> attribute on the variables and subroutines directly. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
As you can see from the Synopsis, the attribute takes an argument |
|
76
|
|
|
|
|
|
|
of the same format as you would give as the hash key for C<Getopt::Long>. |
|
77
|
|
|
|
|
|
|
See the C<Getopt::Long> manpage for details. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Note that since attributes are processed during CHECK, but assignments |
|
80
|
|
|
|
|
|
|
on newly declared variables are processed during run-time, you |
|
81
|
|
|
|
|
|
|
can't set defaults on those variables beforehand, like this: |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
our $verbose : Getopt(verbose!) = 1; # DOES NOT WORK |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Instead, you have to establish defaults afterwards, like so: |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
our $verbose : Getopt(verbose!); |
|
88
|
|
|
|
|
|
|
$verbose ||= 1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Alternatively, you can specify a default value within the C<Getopt> |
|
91
|
|
|
|
|
|
|
attribute: |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
our $def2 : Getopt(def2=i 42); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
To check whether there was an error during C<getopt> processing you can use |
|
96
|
|
|
|
|
|
|
the C<error()> function: |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
pod2usage(-verbose => 2, -exitval => 0) if Getopt::Attribute->error; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 METHODS |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 error |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
FIXME |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 options |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
FIXME |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 INSTALLATION |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
See perlmodinstall for information and options on installing Perl modules. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
No bugs have been reported. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Please report any bugs or feature requests through the web interface at |
|
119
|
|
|
|
|
|
|
L<http://rt.cpan.org>. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AVAILABILITY |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The latest version of this module is available from the Comprehensive Perl |
|
124
|
|
|
|
|
|
|
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN |
|
125
|
|
|
|
|
|
|
site near you, or see |
|
126
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Getopt-Attribute/>. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
The development version lives at |
|
129
|
|
|
|
|
|
|
L<http://github.com/hanekomu/Getopt-Attribute/>. |
|
130
|
|
|
|
|
|
|
Instead of sending patches, please fork this project using the standard git |
|
131
|
|
|
|
|
|
|
and github infrastructure. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 AUTHOR |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Marcel Gruenauer <marcel@cpan.org> |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
This software is copyright (c) 2001 by Marcel Gruenauer. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
142
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|