1 |
commit: c7b4fddfc61341e6a0e7e82e98a84e2fe0e51db8 |
2 |
Author: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
3 |
AuthorDate: Tue Feb 28 21:45:00 2012 +0000 |
4 |
Commit: Kent Fredric <kentfredric <AT> gmail <DOT> com> |
5 |
CommitDate: Tue Feb 28 21:45:00 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/perl-overlay.git;a=commit;h=c7b4fddf |
7 |
|
8 |
[scripts] Rehash module_log.pl to use optparse lib |
9 |
|
10 |
--- |
11 |
scripts/module_log.pl | 40 ++++++++++++---------------------------- |
12 |
1 files changed, 12 insertions(+), 28 deletions(-) |
13 |
|
14 |
diff --git a/scripts/module_log.pl b/scripts/module_log.pl |
15 |
index 92f976b..f92ec36 100755 |
16 |
--- a/scripts/module_log.pl |
17 |
+++ b/scripts/module_log.pl |
18 |
@@ -9,30 +9,13 @@ use warnings; |
19 |
use FindBin; |
20 |
use lib "$FindBin::Bin/lib"; |
21 |
use env::gentoo::perl_experimental; |
22 |
+use optparse; |
23 |
use metacpan qw( mcpan ); |
24 |
|
25 |
-my $flags; |
26 |
-my $singleflags; |
27 |
- |
28 |
-@ARGV = grep { defined } map { |
29 |
- $_ =~ /^--(.+)/ |
30 |
- ? do { $flags->{$1}++; undef } |
31 |
- : do { |
32 |
- $_ =~ /^-(.+)/ |
33 |
- ? do { $singleflags->{$1}++; undef } |
34 |
- : do { $_ } |
35 |
- } |
36 |
-} @ARGV; |
37 |
-for my $f ( keys %{$flags} ) { |
38 |
- if ( $f =~ /^([^=]+)=(.*$)/ ) { |
39 |
- $flags->{$1} = $2; |
40 |
- } |
41 |
-} |
42 |
- |
43 |
-if ( $flags->{help} or $singleflags->{h} ) { print help(); exit 0; } |
44 |
- |
45 |
-sub help { |
46 |
- return <<'EOF'; |
47 |
+my $optparse = optparse->new( |
48 |
+ argv => \@ARGV, |
49 |
+ help => sub { |
50 |
+ return print <<'EOF'; |
51 |
module_log.pl |
52 |
|
53 |
USAGE: |
54 |
@@ -75,7 +58,8 @@ USAGE: |
55 |
# |
56 |
|
57 |
EOF |
58 |
-} |
59 |
+ }, |
60 |
+); |
61 |
|
62 |
# FILENAME: module_log.pl |
63 |
# CREATED: 25/10/11 12:15:51 by Kent Fredric (kentnl) <kentfredric@×××××.com> |
64 |
@@ -88,17 +72,17 @@ EOF |
65 |
|
66 |
use Data::Dump qw( pp ); |
67 |
|
68 |
-my ($release) = shift(@ARGV); |
69 |
+my ($release) = shift( $optparse->extra_opts ); |
70 |
|
71 |
-my (@data) = metacpan->find_dist_simple( $release, $flags ); |
72 |
-if( not $flags->{dump} ) { |
73 |
+my (@data) = metacpan->find_dist_simple( $release, $optparse->long_opts ); |
74 |
+if ( not $optparse->long_opts->{dump} ) { |
75 |
my $result = [ map { $_->{as_string} } @data ]; |
76 |
|
77 |
use JSON qw( to_json ); |
78 |
say to_json( $result, { pretty => 1 } ); |
79 |
-} else { |
80 |
+} |
81 |
+else { |
82 |
pp $_ for @data; |
83 |
} |
84 |
1; |
85 |
|
86 |
- |