Line | |
---|
1 | package MP3::Find::Util; |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | |
---|
6 | use base qw(Exporter); |
---|
7 | use vars qw(@EXPORT_OK); |
---|
8 | |
---|
9 | @EXPORT_OK = qw(build_query); |
---|
10 | |
---|
11 | sub build_query { |
---|
12 | my @args = @_; |
---|
13 | |
---|
14 | # first find all the directories |
---|
15 | my @dirs; |
---|
16 | while (local $_ = shift @args) { |
---|
17 | if (/^-/) { |
---|
18 | # whoops, there's the beginning of the query |
---|
19 | unshift @args, $_; |
---|
20 | last; |
---|
21 | } else { |
---|
22 | push @dirs, $_; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | # now build the query hash |
---|
27 | my %query; |
---|
28 | my $field; |
---|
29 | while (local $_ = shift @args) { |
---|
30 | if (/^--?(.*)/) { |
---|
31 | $field = uc $1; |
---|
32 | } else { |
---|
33 | $field ? push @{ $query{$field} }, $_ : die "Need a field name before value '$_'\n"; |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
37 | return (\@dirs, \%query); |
---|
38 | } |
---|
39 | |
---|
40 | # module return |
---|
41 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.