blib/script/perlws.pl untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 28 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 148 CC 5 SCAR 21.6
CC
5
Cov
0%
ws_confirm
20.0
ws_exit
6.0
BEGIN
2.0
CRAP 8.7
1 #!/usr/local/bin/perl -w
2 use strict;
3 use warnings;
4 use PAR::WebStart;
5 use PAR::WebStart::Util;
6 use constant WIN32 => PAR::WebStart::Util::WIN32;
7
8 if (WIN32()) {
9 require Win32;
10 import Win32 qw(MB_ICONSTOP MB_ICONEXCLAMATION);
11 }
12
13 my $file = shift;
14 my $ws = PAR::WebStart->new(file => $file);
15 $ws->fetch_pars() or ws_exit("Error: $ws->{ERROR}");
16
17 my $title = $ws->{cfg}->{title}->{value} || 'PAR::WebStart application';
18
19 my $tmpdir = $ws->{tmpdir};
20 chdir($tmpdir) or ws_exit(qq{Cannot chdir to "$tmpdir": $!});
21
22 my @args = @{$ws->run_command()};
23 ws_exit(qq{Failed to get WebStart args: $ws->{ERROR}}) unless (@args);
24
25 my $msg = ws_confirm($ws->{cfg});
26
27 if (WIN32) {
28 $msg .= "\nPress OK to continue, or Cancel to quit.";
29 my $rc = Win32::MsgBox($msg, 1 | MB_ICONEXCLAMATION(), $title);
30 exit(1) unless ($rc == 1);
31 system(@args) == 0 or ws_exit(qq{Execution of system(@args) failed: $?});
32 }
33
34 else {
35 my $exec = join ' ', @args;
36 my $cmd = qq{xterm -T "$title" -e "cat<<END\n${msg}\nEND\nread -p 'press \'y\' to continue, or any other key to exit: ' -n1 reply; if test \\\"\\\$reply\\\" = \\\"y\\\"; then echo \\\"\\\n\\\" && $exec;fi"};
37 my $rc = qx{$cmd};
38 ws_exit(qq{Execution of $cmd failed: $rc}) if $rc;
39 }
40
41 if ($ENV{PAR_CLEAN}) {
42 my ($md5, $parfile);
43 foreach $parfile(@{$ws->{pars}}) {
44 $md5 = $parfile . '.md5';
45 next unless (-f $md5 and -f $parfile);
46 unlink($parfile, $md5);
47 }
48 }
49
50 exit(0);
51
52 sub ws_exit {
53 my $string = shift;
54 my $msg = << "END";
55 An error was encoutered in running the application:
56 $string
57 Execution will be terminated.
58 END
59 if (WIN32()) {
60 Win32::MsgBox($msg, 0 | MB_ICONSTOP(), $title);
61 }
62 else {
63 my $cmd = qq{xterm -T "$title" -e "cat<<END\n${msg}\nEND\nread -p 'press any key to continue...' -n1"};
64 my $rc = qx{$cmd};
65 }
66 exit(1);
67 }
68
69 sub ws_confirm {
70 my $cfg = shift;
71
72 my $check_msg = '';
73 if ($cfg->{'allow-unsigned-pars'} && $cfg->{'allow-unsigned-pars'}->{seen}) {
74 $check_msg = <<"END";
75 An md5 checksum of the par archives was performed; however,
76 the provider of the application has disabled checking of
77 the digital signature. You should be very careful in
78 running programs from sources you are unsure of.
79 END
80 }
81 else {
82 $check_msg = <<"END";
83 Although the md5 checksum and the digital signature of the
84 associated par archives have been verified, you should be very
85 careful in running programs from sources you are unsure of.
86 END
87
88 }
89
90 my $argument = $cfg->{argument};
91 my $args = '';
92 if ($argument and ref($argument) eq 'ARRAY') {
93 $args = join ' ', (map {$_->{value}} @$argument);
94 }
95 $args = "with arguments to the main script of:\n $args\n" if $args;
96
97 my $name = $cfg->{title}->{value} || '(no title specified)';
98 my $desc = $cfg->{description}->[0]->{value} || '(no description specified)';
99 my $vendor = $cfg->{vendor}->{value} || '(no vendor specified)';
100 my $home = $cfg->{homepage}->{href} || '(no homepage specified)';
101 my $msg = <<"END";
102 You about to run the program:
103 $name
104 $args
105 The application is described as:
106 $desc
107 and is supplied by:
108 $vendor
109 whose homepage is found at:
110 $home
111
112 $check_msg
113 END
114
115 return $msg;
116 }
117
118 __END__