getweb.pl

filter: Statementstmt 80.0% 8 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 85.7% 12 / 14 CC 1 SCAR 0.7
CC
1
Cov
80%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« MailBot/UI.pm ↑ Summary
1 #!/usr/bin/perl
2 #-
3 #-getweb.pl: sends formatted web pages via e-mail.
4 #-
5 #-Usage:
6 #- $0 [-hvD] [-r root]
7 #- [(-c | -f spool | -i [-s subject] [-b body])]
8 #- [file ...]
9 #-
10 #-Where:
11 #- -i : interactive mode (read in command, send result to STDOUT)
12 #- -s subject : specify subject on command-line
13 #- -b body : specify message body on command-line
14 #- -r root : system root, default is /usr/local/getweb
15 #-
16 #- file ... : files containing mail messages or input (default is STDIN)
17 #- -c : CGI Web-interface mode
18 #- -f spool : read from mail spoolfile 'spool' (example: /var/spool/mail/me)
19 #-
20 #- -h : print this help message and exit
21 #- -v : print the version number and exit
22 #- -D : print debugging information
23 #-
24 #
25 # Version: 1.1 release
26 # Author: Rolf Nelson
27 #
28  
29 my $DEFAULT_ROOT = "/usr/local/getweb";
30  
31 26 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32 26 push(@INC,".");
33 }
34  
35 $ENV{PATH} = "/bin";
36  
37 26 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 26 ▶use MailBot::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 0 ▶use GetWeb::GetWeb;
Subroutine BEGIN: called CC=1 SCAR=2.6
40 use strict;
41  
42 # untaint @ARGV to get around libwww-perl bug
43 grep {/((.|\n)*)/ and $_ = $1} @ARGV;
44 &procOpts();
45  
46 my $root = $::opt_r || $DEFAULT_ROOT;
47 MailBot::Config -> setRoot($root);
48 my $mailBotConfig = MailBot::Config::current();
49  
50 if ($::opt_i)
51 {
52 $mailBotConfig -> setInteractive();
53  
54 (defined $::opt_s) and
55 $mailBotConfig -> setSubject($::opt_s);
56  
57 (defined $::opt_b) and
58 $mailBotConfig -> setBody($::opt_b);
59 }
60  
61 if (defined $::opt_f)
62 {
63 $mailBotConfig -> setMailSpool($::opt_f);
64 }
65 elsif ($::opt_c)
66 {
67 $mailBotConfig -> setCGI();
68 }
69  
70 my $in = shift @ARGV;
71 if (defined $in)
72 {
73 open(STDIN,$in) or die "could not open $in for input: $!";
74 }
75  
76 my $getweb = new GetWeb::GetWeb;
77  
78 $getweb -> run;
79  
80 0;
81  
82 #----------------------------------------------------------------
83 # procOpts: process command-line options
84 #----------------------------------------------------------------
85 sub procOpts
86 {
87 ($::opt_v, $::opt_c, $::opt_h, $::opt_D,
88 $::opt_i, $::opt_r) = (); #avoid warning message
89 getopts('b:cf:ir:s:hvD') || &showUsage("bad command switches");
90 &d();
91 $::opt_h && &showUsage();
92 $::opt_v && &showVersion();
93 }
94  
95 #----------------------------------------------------------------
96 # showUsage : display a usage string, then exit.
97 #----------------------------------------------------------------
98 sub showUsage
99 {
100 my $errMsg = shift;
101 if ($errMsg ne "")
102 {
103 print STDERR "Usage error: $errMsg\n\n";
104 }
105  
106 seek(DATA,0,0);
107 while (<DATA>)
108 {
109 if (s/^\#\-//)
110 {
111 s/\$0/$0/;
112 print STDERR $_ unless /^\-/;
113 }
114 }
115  
116 exit ($errMsg ne "");
117 }
118  
119 #----------------------------------------------------------------
120 # showVersion : print Version and exit.
121 #----------------------------------------------------------------
122 sub showVersion
123 {
124 seek(DATA,0,0);
125 while (<DATA>)
126 {
127 print STDERR $_ if /\s+Version:/;
128 }
129  
130 exit(0);
131 }
132  
133 #----------------------------------------------------------------
134 # d : print debugging message if -D verbose flag is on.
135 #----------------------------------------------------------------
136 sub d
137 {
138 return unless $::opt_D;
139 my $msg = shift;
140 if ($msg eq "")
141 {
142 print STDERR "found -D flag; running $0 in verbose DEBUG mode.\n";
143 }
144 else
145 {
146 print STDERR $msg, "\n";
147 }
148 }
149  
150 __END__
« MailBot/UI.pm ↑ Summary