| 1 | #!/usr/local/bin/perl |
| 2 | |
| 3 | # Original authors: don |
| 4 | # $Revision: $ |
| 5 | |
| 6 | |
| 7 | use strictscip-perl cpan Pod-POM-View-Restructured 1.000004 strict/; |
| 8 | use warningsscip-perl cpan Pod-POM-View-Restructured 1.000004 warnings/; |
| 9 | use Carpscip-perl cpan Pod-POM-View-Restructured 1.000004 Carp/; |
| 10 | use Getopt::Longscip-perl cpan Pod-POM-View-Restructured 1.000004 Getopt/Long/ qw(:config no_ignore_case bundling); |
| 11 | use Data::Dumperscip-perl cpan Pod-POM-View-Restructured 1.000004 Data/Dumper/ (); |
| 12 | |
| 13 | use Pod::POMscip-perl cpan Pod-POM-View-Restructured 1.000004 Pod/POM/; |
| 14 | |
| 15 | # main |
| 16 | { |
| 17 | # local($SIG{__DIE__}) = sub { &Carp::confess }; |
| 18 | my $self = blessscip-perl cpan Pod-POM-View-Restructured 1.000004 main/bless(). { }; |
| 19 | |
| 20 | my $opts = $self->get_optionsscip-perl cpan Pod-POM-View-Restructured 1.000004 main/get_options().([ "help|h" ], { }); |
| 21 | $self->check_optionsscip-perl cpan Pod-POM-View-Restructured 1.000004 main/check_options().($opts, [ ]); # die's on bad options |
| 22 | |
| 23 | |
| 24 | my $top_dir; |
| 25 | # Set up @INC to get right version of module |
| 26 | use File::Specscip-perl cpan Pod-POM-View-Restructured 1.000004 File/Spec/ (); |
| 27 | BEGIN { |
| 28 | my $path = File::Spec->rel2absscip-perl cpan Pod-POM-View-Restructured 1.000004 File/Spec/rel2abs().($0scip-perl cpan Pod-POM-View-Restructured 1.000004 main/$0.); |
| 29 | (my $dir = $path) =~ s{(?:/[^/]+){2}\Z}{}; |
| 30 | # unshift @INC, $dir . "/blib/lib", $dir . "/blib/arch"; |
| 31 | unshiftscip-perl cpan Pod-POM-View-Restructured 1.000004 main/unshift(). @INCscip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@INC`., $dir . "/lib"; |
| 32 | |
| 33 | $top_dir = $dir; |
| 34 | } |
| 35 | |
| 36 | my $test_dir = $top_dir . "/test_doc/source"; |
| 37 | my $doc_dir = $top_dir . "/test_doc"; |
| 38 | my $base_dir = "/owens_lib/cpan"; |
| 39 | |
| 40 | # my $dest_dir = "$top_dir/test_doc/big_out"; |
| 41 | my $dest_dir = "$top_dir/test_doc/source"; |
| 42 | |
| 43 | |
| 44 | use Pod::POM::View::Restructuredscip-perl cpan Pod-POM-View-Restructured 1.000004 Pod/POM/View/Restructured/; |
| 45 | |
| 46 | my $link_cb = sub { |
| 47 | my ($text) = @_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.; |
| 48 | |
| 49 | if ($text eq 'DBIx::Wrapper::Request') { |
| 50 | return ('DBIx-Wrapper-Request.html', $text); |
| 51 | } |
| 52 | |
| 53 | return; |
| 54 | }; |
| 55 | |
| 56 | my $callbacks = { link => $link_cb }; |
| 57 | |
| 58 | chdirscip-perl cpan Pod-POM-View-Restructured 1.000004 main/chdir(). $dest_dir; |
| 59 | |
| 60 | my $files = [ |
| 61 | { source_file => "$base_dir/Pod-POM-View-Restructured/lib/Pod/POM/View/Restructured.pm", |
| 62 | dest_file => "Pod-POM-View-Restructured.rst", |
| 63 | callbacks => $callbacks, |
| 64 | }, |
| 65 | { source_file => "$base_dir/JSON-DWIW/lib/JSON/DWIW.pm", |
| 66 | dest_file => "JSON-DWIW.rst", |
| 67 | callbacks => $callbacks, |
| 68 | }, |
| 69 | { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper.pm", |
| 70 | dest_file => 'DBIx-Wrapper.rst', |
| 71 | callbacks => $callbacks, |
| 72 | }, |
| 73 | |
| 74 | { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper/Request.pm", |
| 75 | dest_file => 'DBIx-Wrapper-Request.rst', |
| 76 | callbacks => $callbacks, |
| 77 | no_toc => 1, |
| 78 | }, |
| 79 | |
| 80 | ]; |
| 81 | |
| 82 | my $conv = Pod::POM::View::Restructured->newscip-perl cpan Pod-POM-View-Restructured 1.000004 Pod/POM/View/Restructured/new().; |
| 83 | |
| 84 | |
| 85 | my $rv = $conv->convert_filesscip-perl cpan Pod-POM-View-Restructured 1.000004 Pod/POM/View/Restructured/convert_files().($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir); |
| 86 | |
| 87 | print STDERR Data::Dumpscip-perl cpan Pod-POM-View-Restructured 1.000004 Data/Dumper/Dump().er->Dump([ $rv ], [ 'rv' ]) . "\n\n"; |
| 88 | |
| 89 | chdirscip-perl cpan Pod-POM-View-Restructured 1.000004 main/chdir(). $doc_dir or diescip-perl cpan Pod-POM-View-Restructured 1.000004 main/die(). "couldn't chdir to $doc_dir"; |
| 90 | |
| 91 | my @cmd = ('make', 'html'); |
| 92 | systemscip-perl cpan Pod-POM-View-Restructured 1.000004 main/system(). {$cmd[0]} @cmd; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | exitscip-perl cpan Pod-POM-View-Restructured 1.000004 main/exit(). 0; |
| 97 | |
| 98 | ############################################################################### |
| 99 | # Subroutines |
| 100 | |
| 101 | ########## begin option processing ########## |
| 102 | sub print_usagescip-perl cpan Pod-POM-View-Restructured 1.000004 main/print_usage(). { |
| 103 | print STDERR qq{\nUsage: @{[ ($0 =~ m{\A.*/([^/]+)\Z})[0] || $0 ]} options |
| 104 | |
| 105 | Options: |
| 106 | |
| 107 | [-h | --help] # this help msg |
| 108 | \n}; |
| 109 | } |
| 110 | |
| 111 | sub check_optionsscip-perl cpan Pod-POM-View-Restructured 1.000004 main/check_options(). { |
| 112 | my ($self, $opts, $required) = @_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.; |
| 113 | |
| 114 | if (not $opts or $opts->{help}) { |
| 115 | $self->print_usagescip-perl cpan Pod-POM-View-Restructured 1.000004 main/print_usage().; |
| 116 | exitscip-perl cpan Pod-POM-View-Restructured 1.000004 main/exit(). 1; |
| 117 | } |
| 118 | |
| 119 | my $opt_ok = 1; |
| 120 | $required = [ ] unless $required; |
| 121 | foreach my $key (@$required) { |
| 122 | if (definedscip-perl cpan Pod-POM-View-Restructured 1.000004 main/defined().($opts->{$key})) { |
| 123 | if (my $v = $opts->{$key}) { |
| 124 | if (my $ref = refscip-perl cpan Pod-POM-View-Restructured 1.000004 main/ref().($v)) { |
| 125 | if ($ref eq 'ARRAY' ) { |
| 126 | unless (@$v) { |
| 127 | $opt_ok = 0; |
| 128 | warnscip-perl cpan Pod-POM-View-Restructured 1.000004 main/warn(). "missing required option '$key' |
| 129 | "; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | else { |
| 136 | $opt_ok = 0; |
| 137 | warnscip-perl cpan Pod-POM-View-Restructured 1.000004 main/warn(). "missing required option '$key'\n"; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | unless ($opt_ok) { |
| 142 | $self->print_usagescip-perl cpan Pod-POM-View-Restructured 1.000004 main/print_usage().; |
| 143 | exitscip-perl cpan Pod-POM-View-Restructured 1.000004 main/exit(). 1; |
| 144 | } |
| 145 | |
| 146 | return $opt_ok; |
| 147 | } |
| 148 | |
| 149 | sub get_optionsscip-perl cpan Pod-POM-View-Restructured 1.000004 main/get_options(). { |
| 150 | my ($self, $spec, $defaults) = @_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.; |
| 151 | my %opts = $defaults ? %$defaults : (); |
| 152 | $spec = [ ] unless $spec; |
| 153 | |
| 154 | my $process_opt = sub { |
| 155 | my ($key, $val) = @_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.; |
| 156 | |
| 157 | if (scalarscip-perl cpan Pod-POM-View-Restructured 1.000004 main/scalar().(@_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.) > 2) { |
| 158 | $opts{$key}{$val} = $_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/`@_`.[2]; |
| 159 | } |
| 160 | else { |
| 161 | if ( existsscip-perl cpan Pod-POM-View-Restructured 1.000004 main/exists().($opts{$key}) and (my $v = $opts{$key}) ) { |
| 162 | if (my $ref = refscip-perl cpan Pod-POM-View-Restructured 1.000004 main/ref().($v)) { |
| 163 | if ($ref eq 'ARRAY' ) { |
| 164 | pushscip-perl cpan Pod-POM-View-Restructured 1.000004 main/push(). @{ $opts{$key} }, $val; |
| 165 | return 1; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | $opts{$key} = $val; |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | my $opt_rv = Getopt::Long::GetOptionsscip-perl cpan Pod-POM-View-Restructured 1.000004 Getopt/Long/GetOptions().(mapscip-perl cpan Pod-POM-View-Restructured 1.000004 main/map(). { ($_scip-perl cpan Pod-POM-View-Restructured 1.000004 main/$_. => $process_opt) } @$spec); |
| 175 | |
| 176 | return $opt_rv ? \%opts : undef; |
| 177 | } |
| 178 | ########## end option processing ########## |