]> git.donarmstrong.com Git - bugscan.git/blob - t/test_spool/versions/indices/dump_stub_from_index.pl
sort keys before dumping them
[bugscan.git] / t / test_spool / versions / indices / dump_stub_from_index.pl
1 #!/usr/bin/perl
2 # dump_stub_from_index.pl Outputs stubs from a tied index
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
5 # more information.
6 # Copyright 2014 by Don Armstrong <don@donarmstrong.com>.
7
8
9 use warnings;
10 use strict;
11
12 use Getopt::Long;
13 use Pod::Usage;
14
15 =head1 NAME
16
17 dump_stub_from_index.pl - Outputs stubs from a tied index
18
19 =head1 SYNOPSIS
20
21 dump_stub_from_index.pl index.idx key1 [key2...]
22
23  Options:
24    --debug, -d debugging level (Default 0)
25    --help, -h display this help
26    --man, -m display manual
27
28 =head1 OPTIONS
29
30 =over
31
32 =item B<--debug, -d>
33
34 Debug verbosity. (Default 0)
35
36 =item B<--help, -h>
37
38 Display brief usage information.
39
40 =item B<--man, -m>
41
42 Display this manual.
43
44 =back
45
46 =head1 EXAMPLES
47
48 dump_stub_from_index.pl
49
50 =cut
51
52
53 use vars qw($DEBUG);
54 use MLDBM qw(DB_File Storable);
55 # Use the portable dump method
56 $MLDBM::DumpMeth=q(portable);
57 use Data::Dumper;
58 # sort Data::Dumper keys
59 $Data::Dumper::Sortkeys=1;
60 use Fcntl;
61 use File::Basename;
62
63
64 my %options = (debug           => 0,
65                help            => 0,
66                man             => 0,
67               );
68
69 GetOptions(\%options,
70            'debug|d+','help|h|?','man|m');
71
72 pod2usage() if $options{help};
73 pod2usage({verbose=>2}) if $options{man};
74
75 $DEBUG = $options{debug};
76
77 my @USAGE_ERRORS;
78 if (@ARGV < 2) {
79     push @USAGE_ERRORS,"You must give an index and at least one stub";
80 }
81
82 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
83
84 my ($index,@stubs) = @ARGV;
85
86 print "# dump_stub_from_index.pl ".basename($index)." ".join(' ',@stubs)."\n";
87 my %db;
88 tie %db, "MLDBM",$index, O_RDONLY
89     or die "Unable to open and tie $index for reading: $!";
90
91 my %object;
92 for my $stub (@stubs) {
93     $object{$stub} = $db{$stub};
94 }
95 print Data::Dumper->Dump([\%object],[qw($stub)]);
96
97
98
99
100 __END__