Debian Codegraph @

bin/htmlcopy

raw
1 #!/usr/bin/env perl -w
2
3 use strict;
4 use File::Basename;
5 use File::Spec;
6 use HTML::Copy;
7 use Getopt::Long;
8 use Pod::Usage;
9
10 our $VERSION = '1.31';
11
12 {
13 my $man = 0;
14 my $help = 0;
15
16 GetOptions('help|?' => \$help, man => \$man) or pod2usage(2);
17 pod2usage(-exitstatus => 0, -verbose => 1) if $help;
18 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
19
20 if (@ARGV > 2) {
21 pod2usage(-message => 'Too many arguments.',
22 -exitstatus => 1, -verbose => 1)
23 }
24
25 if (@ARGV < 1) {
26 pod2usage(-message => 'Required arguments is not given.',
27 -exitstatus => 1, -verbose => 1)
28 }
29
30 my ($source_path, $target_path) = @ARGV;
31
32 my $in;
33 if ($source_path eq '-' ) {
34 open $in , " -";
35 } else {
36 $in = $source_path;
37 }
38
39 my $p = HTML::Copy->new($in);
40 #$p->set_encode_suspects(qw/euc-jp shiftjis 7bit-jis/);
41 unless ($target_path) {
42 open $target_path, ">-";
43 }
44 $p->copy_to($target_path);
45 }
46
47 1;
48
49 __END__
50
51 =head1 NAME
52
53 htmlcopy -- Copy a HTML file without breaking links.
54
55 =head1 SYNOPSIS
56
57 htmlcopy [OPTION] {SOURCE | -} [DESTINATION]
58
59 =head1 DESCRIPTION
60
61 htmlcopy a source HTML file into DESTINATION. If the HTML file have links to images, other HTML files, javascripts and cascading style sheets, htmlcopy changing link path in the HTML file to keep the link destination.
62
63 When DESTINATION is omitted, the modified HTML is written in the standard output. Also it is assumed that output location is the current working directory.
64
65 SOURCE and DESTINATION should be cleanuped pathes. For example, a verbose path like '/aa/bb/../cc' may cause converting links wrongly. This is a limitaion of the URI module's rel method. To cleanup pathes, Cwd::realpath is useful.
66
67 =head1 OPTIONS
68
69 =over 4
70
71 =item -h, --help
72
73 Print a brief help message and exits.
74
75 =item -m, --man
76
77 Prints the manual page and exits.
78
79 =back
80
81 =head1 AUTHOR
82
83 Tetsuro KURITA <[email protected]>
84
85 =cut