File: test2.pl

package info (click to toggle)
libpod-pom-view-restructured-perl 1.000003-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 668; makefile: 2
file content (178 lines) | stat: -rwxr-xr-x 4,471 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/local/bin/perl

# Original authors: don
# $Revision: $


use strict;
use warnings;
use Carp;
use Getopt::Long qw(:config no_ignore_case bundling);
use Data::Dumper ();

use Pod::POM;

# main
{
    # local($SIG{__DIE__}) = sub { &Carp::confess };
    my $self = bless { };

    my $opts = $self->get_options([ "help|h" ], { });
    $self->check_options($opts, [ ]); # die's on bad options


    my $top_dir;
    # Set up @INC to get right version of module
    use File::Spec ();
    BEGIN {
        my $path = File::Spec->rel2abs($0);
        (my $dir = $path) =~ s{(?:/[^/]+){2}\Z}{};
        # unshift @INC, $dir . "/blib/lib", $dir . "/blib/arch";
        unshift @INC, $dir . "/lib";

        $top_dir = $dir;
    }

    my $test_dir = $top_dir . "/test_doc/source";
    my $doc_dir = $top_dir . "/test_doc";
    my $base_dir = "/owens_lib/cpan";

    # my $dest_dir = "$top_dir/test_doc/big_out";
    my $dest_dir = "$top_dir/test_doc/source";


    use Pod::POM::View::Restructured;

    my $link_cb = sub {
        my ($text) = @_;

        if ($text eq 'DBIx::Wrapper::Request') {
            return ('DBIx-Wrapper-Request.html', $text);
        }

        return;
    };

    my $callbacks = { link => $link_cb };

    chdir $dest_dir;
    
    my $files = [
                 { source_file => "$base_dir/Pod-POM-View-Restructured/lib/Pod/POM/View/Restructured.pm",
                   dest_file => "Pod-POM-View-Restructured.rst",
                   callbacks => $callbacks,
                 },
                 { source_file => "$base_dir/JSON-DWIW/lib/JSON/DWIW.pm",
                   dest_file => "JSON-DWIW.rst",
                   callbacks => $callbacks,
                 },
                 { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper.pm",
                   dest_file => 'DBIx-Wrapper.rst',
                   callbacks => $callbacks,
                 },

                 { source_file => "$base_dir/DBIx/Wrapper/DBIx-Wrapper/lib/DBIx/Wrapper/Request.pm",
                   dest_file => 'DBIx-Wrapper-Request.rst',
                   callbacks => $callbacks,
                   no_toc => 1,
                 },

                ];

    my $conv = Pod::POM::View::Restructured->new;


    my $rv = $conv->convert_files($files, "$dest_dir/index.rst", 'My Big Test', $dest_dir);

    print STDERR Data::Dumper->Dump([ $rv ], [ 'rv' ]) . "\n\n";

    chdir $doc_dir or die "couldn't chdir to $doc_dir";

    my @cmd = ('make', 'html');
    system {$cmd[0]} @cmd;

}

exit 0;

###############################################################################
# Subroutines

########## begin option processing ##########
sub print_usage {
    print STDERR qq{\nUsage: @{[ ($0 =~ m{\A.*/([^/]+)\Z})[0] || $0 ]} options

    Options:

        [-h | --help]    # this help msg
\n};
}

sub check_options {
    my ($self, $opts, $required) = @_;

    if (not $opts or $opts->{help}) {
        $self->print_usage;
        exit 1;
    }

    my $opt_ok = 1;
    $required = [ ] unless $required;
    foreach my $key (@$required) {
        if (defined($opts->{$key})) {
            if (my $v = $opts->{$key}) {
                if (my $ref = ref($v)) {
                    if ($ref eq 'ARRAY' ) {
                        unless (@$v) {
                            $opt_ok = 0;
                            warn "missing required option '$key'
";
                        }
                    }
                }
            }
        }
        else {
            $opt_ok = 0;
            warn "missing required option '$key'\n";
        }
    }

    unless ($opt_ok) {
        $self->print_usage;
        exit 1;
    }

    return $opt_ok;
}

sub get_options {
    my ($self, $spec, $defaults) = @_;
    my %opts = $defaults ? %$defaults : ();
    $spec = [ ] unless $spec;

    my $process_opt = sub {
        my ($key, $val) = @_;

        if (scalar(@_) > 2) {
            $opts{$key}{$val} = $_[2];
        }
        else {
            if ( exists($opts{$key}) and (my $v = $opts{$key}) ) {
                if (my $ref = ref($v)) {
                    if ($ref eq 'ARRAY' ) {
                        push @{ $opts{$key} }, $val;
                        return 1;
                    }
                }
            }

            $opts{$key} = $val;
        }
    };

    my $opt_rv = Getopt::Long::GetOptions(map { ($_ => $process_opt) } @$spec);

    return $opt_rv ? \%opts : undef;
}
########## end option processing ##########