blib/lib/Alien/BatToExeConverter.pm

filter: Statementstmt 56.8% 25 / 44 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 88.8% 8 / 9 Podpod 100% 2 / 2 totaltotal 41.3% 36 / 87 CC 11 SCAR 40.7
CC
11
Cov
38%
bat2exe
110.0
bat2exe_path
2.0
BEGIN
1.0
CRAP 58.5
↑ Summary
1 package Alien::BatToExeConverter;
2  
3 =pod
4  
5 =head1 NAME
6  
7 Alien::BatToExeConverter - Convert a DOS Batch Script to an Executable
8  
9 =head1 SYNOPSIS
10  
11 # Convert a batch script to an executable that won't show a DOS box
12 Alien::BatToExeConverter::bat2exe(
13 bat => 'C:\strawberry\perl\bin\foo.bat',
14 exe => 'C:\strawberry\perl\bin\foo.exe',
15 );
16  
17 =head1 DESCRIPTION
18  
19 F<Bat_To_Exe_Converter.exe> is a nice little Windows Freeware program,
20 built from open source elements, that will take a batch script and
21 convert it into an executable (both as a command-line form, and as a
22 GUI form).
23  
24 =head1 FUNCTIONS
25  
26 =cut
27  
28 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use File::Which ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use IPC::Run3 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 2 our $VERSION = '0.01';
37  
38 =pod
39  
40 =head2 bat2exe_path
41  
42 The C<bat2exe> function is used to locate the F<Bat_To_Exe_Converter.exe>
43 tool on the host. The Alien module will look in the local binary search
44 path, and then if a local version can't be found, it will instead return
45 the path to a bundled version.
46  
47 =cut
48  
49 1 ▶sub bat2exe_path {
Subroutine bat2exe_path: called CC=2 SCAR=7.1
Pod documented
50 # Check for the installed version
51 1 my $installed = File::Which::which('Bat_To_Exe_Converter');
52 1 ▶ return $installed if $installed;
Branch: 1 branch
BranchTrueFalseTotal
if $installed 0 1 1
53  
54 # Default to the bundled version
55 1 File::ShareDir::dist_file(
56 'Alien-BatToExeConverter',
57 'Bat_To_Exe_Converter.exe',
58 );
59 }
60  
61 =pod
62  
63 =head2 bat2exe
64  
65 # Convert a batch script to an executable that will have an icon,
66 # won't show a DOS box, and will suppress to the command line.
67 Alien::BatToExeConverter::bat2exe(
68 bat => 'C:\strawberry\perl\bin\foo.bat',
69 exe => 'C:\strawberry\perl\bin\foo.exe',
70 ico => 'C:\strawberry\perl\bin\foo.ico',
71 dos => 0,
72 );
73  
74 The C<bat2exe> function is used to execute F<Bat_To_Exe_Converter.exe> and
75 generate an executable from the batch script. It takes a series of named
76 params, returning true on success or throwing an exception on failure.
77 The default settings are intended to produce an .exe script for launching
78 a GUI application.
79  
80 The compulsory C<bat> param should be the name of the source batch script.
81  
82 The compulsory C<exe> param should be the path to white the executable to,
83 and must NOT already exist.
84  
85 The optional C<ico> param will bind an icon to the executable.
86  
87 The optional C<dos> param will indicate that the executable is intended
88 for the command line. If C<not> supplied, STDOUT and STDERR will be
89 supressed and a "DOS box" will not be shown on execution.
90  
91 =cut
92  
93 0 ▶sub bat2exe {
Subroutine bat2exe: not called CC=10 SCAR=47.0
Pod documented
94 0 my %param = @_;
95  
96 # Required input batch script
97 0 my $bat = $param{bat};
98 0 ▶ unless ( $bat and $bat =~ /\.bat$/ and -f $bat ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bat and $bat =~ /\.bat$/ and -f $bat) 0 0 0
Condition0%0/6
$bat and $bat =~ /\.bat$/ and -f $bat
!ll&&!rl&&r
000
$bat and $bat =~ /\.bat$/
!ll&&!rl&&r
000
MC/DC0%0/3
$bat and $bat =~ /\.bat$/ and -f $bat
$bat $bat =~ /\.bat$/ -f $bat
Truth table0%0/4
A and B and C
A= $batB= $bat =~ /\.bat$/C= -f $bat
ABCresult
0XX0
10X0
1100
1111
99 0 Carp::croak("Missing or invalid bat file");
100 }
101  
102 # Required output executable application
103 0 my $exe = $param{exe};
104 0 ▶ unless ( $exe and $exe =~ /\.exe$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exe and $exe =~ /\.exe$/) 0 0 0
Condition0%0/3
$exe and $exe =~ /\.exe$/
!ll&&!rl&&r
000
MC/DC0%0/2
$exe and $exe =~ /\.exe$/
$exe $exe =~ /\.exe$/
Truth table0%0/3
A and B
A= $exeB= $exe =~ /\.exe$/
ABresult
0X0
100
111
105 0 Carp::croak("Missing or invalid exe file");
106 }
107 0 ▶ if ( -f $exe ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $exe) 0 0 0
108 0 Carp::croak("The target exe '$exe' already exists");
109 }
110  
111 # Optional icon file
112 0 ▶ my $ico = $param{ico} || '';
Condition0%0/2
$param{'ico'} || ''
l!l
00
MC/DC0%0/1
$param{'ico'} || ''
$param{'ico'}
Truth table0%0/2
A
A= $param{'ico'}
Aresult
11
00
113 0 ▶ if ( $ico and not -f $ico ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ico and not -f $ico) 0 0 0
Condition0%0/3
$ico and not -f $ico
!ll&&!rl&&r
000
MC/DC0%0/2
$ico and not -f $ico
$ico not -f $ico
Truth table0%0/3
A and not(B)
A= $icoB= not -f $ico
ABresult
0X0
100
111
114 0 Carp::croak("Invalid ico file");
115 }
116  
117 # DOS or GUI application?
118 0 my $dos = !! $param{dos};
119  
120 # Hand off to the executable
121 0 my $bat2exe = bat2exe_path();
122 0 my $stdin = '';
123 0 my $stdout = '';
124 0 my $stderr = '';
125 0 my $rv = IPC::Run3::run3( [
126 $bat2exe, $bat, $exe, $ico, $dos,
127 ], \$stdin, \$stdout, \$stderr );
128  
129
130  
131 0 1;
132 }
133  
134 2 1;
135  
136 =pod
137  
138 =head1 SUPPORT
139  
140 Bugs should be submitted via the CPAN bug tracker, located at
141  
142 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Alien-BatToExeConverter>
143  
144 For general comments, contact the author.
145  
146 =head1 AUTHOR
147  
148 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
149  
150 =head1 COPYRIGHT
151  
152 B<Alien::BatToExeConverter> Copyright 2009 Adam Kennedy.
153  
154 This program is free software; you can redistribute
155 it and/or modify it under the same terms as Perl itself.
156  
157 The full text of the license can be found in the
158 LICENSE file included with this module.
159  
160 B<Bat_To_Exe_Converter.exe> Copyright 2006 - 2009 Fatih Kodak.
161  
162 In order to use this program, you must read and agree with this
163 license agreement.
164  
165 You may not translate, reverse program, disassemble, decompile or otherwise
166 reverse engineer this program.
167  
168 No warranty. The software is licensed to you "as is" and without any
169 warranty.
170  
171 If you do not agree with this agreement, please do not use this software.
172  
173 B<Flat Assembler> Copyright 1999 - 2007 Tomasz Grysztar. All rights reserved.
174  
175 This program is free for commercial and non-commercial use as long as
176 the following conditions are adhered to.
177  
178 Copyright remains Tomasz Grysztar, and as such any Copyright notices
179 in the code are not to be removed.
180  
181 Redistribution and use in source and binary forms, with or without
182 modification, are permitted provided that the following conditions are
183 met:
184  
185 1. Redistributions of source code must retain the above copyright notice,
186 this list of conditions and the following disclaimer.
187 2. Redistributions in binary form must reproduce the above copyright
188 notice, this list of conditions and the following disclaimer in the
189 documentation and/or other materials provided with the distribution.
190  
191 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
192 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
193 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
194 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
195 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
196 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
197 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
198 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
199 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
200 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
201 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
202  
203 The licence and distribution terms for any publically available
204 version or derivative of this code cannot be changed. i.e. this code
205 cannot simply be copied and put under another distribution licence
206 (including the GNU Public Licence).
207  
208 =cut
↑ Summary