XUL.pm

filter: Statementstmt 25.9% 27 / 104 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 35.0% 7 / 20 Podpod 60.0% 3 / 5 totaltotal 22.5% 37 / 164 CC 17 SCAR 31.2
CC
17
Cov
20%
bundle
72.0
_get_file_startpl
30.0
_get_file_macosx_xulfiles
12.0
CRAP 22.8
« XUL/Object.pm ↑ Summary
1 package App::XUL;
2  
3 1 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Directory::Scratch::Structured qw(create_structured_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Copy::Recursive qw(fcopy dircopy);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #use Data::Dumper;
9 1 ▶use Data::Dumper::Concise;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use App::XUL::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 require Exporter;
13 1 our @ISA = qw(Exporter);
14 1 our @EXPORT = qw(AUTOLOAD);
15  
16 1 our $VERSION = '0.07';
17 1 our $AUTOLOAD;
18  
19 1 our $Singleton;
20  
21 ################################################################################
22  
23 sub AUTOLOAD
24 0 ▶{
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
25 #print "auto1\n";
26 0 $App::XUL::XML::AUTOLOAD = $AUTOLOAD;
27 0 return App::XUL::XML::AUTOLOAD(@_);
28 }
29  
30 ################################################################################
31  
32 sub new
33 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
34 0 my ($class, @args) = @_;
35 0 my $self = bless {}, $class;
36 0 $Singleton = $self;
37 0 return $self->init(@args);
38 }
39  
40 sub init
41 0 ▶{
Subroutine init: not called CC=2 SCAR=17.9
Pod undocumented
42 0 my ($self, %opts) = @_;
43 0 ▶ $self->{'name'} = $opts{'name'} || do { die "Error: no app name given - new(name => <string>)\n" };
Condition0%0/3
$opts{'name'} || do { die "Error: no app name given - new(name => <string>)\n" }
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{'name'} || do { die "Error: no app name given - new(name => <string>)\n" }
$opts{'name'} do { die "Error: no app name given - new(name => <string>)\n" }
Truth table0%0/3
A || B
A= $opts{'name'}B= do { die "Error: no app name given - new(name => <string>)\n" }
ABresult
1X1
011
000
44 0 $self->{'windows'} = [];
45 0 $self->{'bindings'} = {};
46 0 return $self
47 }
48  
49 sub bind
50 0 ▶{
Subroutine bind: not called CC=1 SCAR=6.9
Pod undocumented
51 0 my ($id, $event, $coderef) = @_;
52 0 $Singleton->{'bindings'}->{$id.':'.$event} = $coderef;
53 0 return $Singleton;
54 }
55  
56 sub add
57 0 ▶{
Subroutine add: not called CC=2 SCAR=17.9
Pod documented
58 0 my ($self, $window_xml) = @_;
59 0 ▶ die "Error: add() only accepts a single window tag as first argument\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $window_xml =~ /^<window/ 0 0 0
60 if $window_xml !~ /^<window/;
61 0 push @{$self->{'windows'}}, $window_xml;
62 0 return $self;
63 }
64  
65 sub bundle
66 0 ▶{
Subroutine bundle: not called CC=8 SCAR=42.8
Pod documented
67 0 my ($self, %opts) = @_;
68
69 0 ▶ my $os = $opts{'os'} || die "Error: no os given - bundle(os => <string>)\n";
Condition0%0/2
$opts{'os'} || die("Error: no os given - bundle(os => <string>)\n")
l!l
00
MC/DC0%0/1
$opts{'os'} || die("Error: no os given - bundle(os => <string>)\n")
$opts{'os'}
Truth table0%0/2
A
A= $opts{'os'}
Aresult
11
00
70 0 ▶ my $path = $opts{'path'} || die "Error: no path given - bundle(path => <string>)\n";
Condition0%0/2
$opts{'path'} || die("Error: no path given - bundle(path => <string>)\n")
l!l
00
MC/DC0%0/1
$opts{'path'} || die("Error: no path given - bundle(path => <string>)\n")
$opts{'path'}
Truth table0%0/2
A
A= $opts{'path'}
Aresult
11
00
71 0 ▶ my $utilspath = $opts{'utilspath'} || die "Error: no utils path given - bundle(utilspath => <string>)\n";
Condition0%0/2
$opts{'utilspath'} || die("Error: no utils path given - bundle(utilspath => <string>)\n")
l!l
00
MC/DC0%0/1
$opts{'utilspath'} || die("Error: no utils path given - bundle(utilspath => <string>)\n")
$opts{'utilspath'}
Truth table0%0/2
A
A= $opts{'utilspath'}
Aresult
11
00
72 0 ▶ $self->{'debug'} = $opts{'debug'} || 0;
Condition0%0/2
$opts{'debug'} || 0
l!l
00
MC/DC0%0/1
$opts{'debug'} || 0
$opts{'debug'}
Truth table0%0/2
A
A= $opts{'debug'}
Aresult
11
00
73
74 #print Dumper($self);
75 #exit;
76
77 ##############################################################################
78 0 ▶ if ($os eq 'chrome') {
Branch: 2 branches
BranchTrueFalseTotal
if ($os eq 'chrome') { } 0 0 0
elsif ($os eq 'macosx') { } 0 0 0
79
80 0 my $name = $self->{'name'};
81
82 0 my $tmpdir = create_structured_tree(
83 $name => {
84 'start_macosx.pl' => [$self->_get_file_startpl('chrome','macosx')],
85 'start_win.pl' => [$self->_get_file_startpl('chrome','win')],
86 'start_linux.pl' => [$self->_get_file_startpl('chrome','linux')],
87 'chrome.manifest' => ['manifest chrome/chrome.manifest'."\n"],
88 'application.ini' => [$self->_get_file_macosx_appini()],
89 #'MyApp.icns' => [],
90 'chrome' => {
91 # for older XUL.framework's we need the chrome.manifest here!
92 'chrome.manifest' => [$self->_get_file_macosx_chromemanifest()],
93 'content' => {
94 #'AppXUL.js' => [],
95 #'AppXULServer.js' => [],
96 $self->_get_file_macosx_xulfiles(),
97 #'main.xul' => [$self->_get_file_macosx_mainxul()],
98 },
99 },
100 'defaults' => {
101 'preferences' => {
102 'prefs.js' => [$self->_get_file_macosx_prefs()],
103 },
104 },
105 'perl' => {
106 'server' => {
107 #'server.pl' => [$self->_get_file_macosx_serverpl()],
108 },
109 'modules' => {
110 'Eventhandlers.pm' => [$self->_get_file_macosx_eventhandlers()],
111 'App' => {
112 'XUL' => {
113 #'XML' => [],
114 #'Object' => [],
115 },
116 },
117 },
118 },
119 'extensions' => {},
120 'updates' => {
121 '0' => {},
122 },
123 }
124 );
125
126 # copy misc files into tmpdir
127  
128 0 fcopy($utilspath.'/AppXUL.js',
129 $tmpdir->base().'/'.$name.'/chrome/content/AppXUL.js');
130  
131 0 fcopy($utilspath.'/server.pl',
132 $tmpdir->base().'/'.$name.'/perl/server/server.pl');
133  
134 0 fcopy($utilspath.'/../lib/App/XUL/XML.pm',
135 $tmpdir->base().'/'.$name.'/perl/modules/App/XUL/XML.pm');
136  
137 0 fcopy($utilspath.'/../lib/App/XUL/Object.pm',
138 $tmpdir->base().'/'.$name.'/perl/modules/App/XUL/Object.pm');
139  
140 # chmod certain files
141 0 chmod(0755, $tmpdir->base().'/'.$name.'/start_macosx.pl');
142 0 chmod(0755, $tmpdir->base().'/'.$name.'/start_win.pl');
143 0 chmod(0755, $tmpdir->base().'/'.$name.'/start_linux.pl');
144  
145 # move tmpdir to final destination
146 0 rename($tmpdir->base().'/'.$name, $path);
147
148 }
149 ##############################################################################
150 elsif ($os eq 'macosx') {
151  
152 0 my $name = $self->{'name'};
153  
154 0 my $tmpdir = create_structured_tree(
155 $name.'.app' => {
156 'Contents' => {
157 'Info.plist' => [$self->_get_file_maxosx_infoplist()],
158 'Frameworks' => {
159 #'XUL.framework' => {},
160 },
161 'MacOS' => {
162 'start.pl' => [$self->_get_file_startpl('macosx')],
163 },
164 'Resources' => {
165 'chrome.manifest' => ['manifest chrome/chrome.manifest'."\n"],
166 'application.ini' => [$self->_get_file_macosx_appini()],
167 #'MyApp.icns' => [],
168 'chrome' => {
169 # for older XUL.framework's we need the chrome.manifest here!
170 'chrome.manifest' => [$self->_get_file_macosx_chromemanifest()],
171 'content' => {
172 #'AppXUL.js' => [],
173 #'AppXULServer.js' => [],
174 $self->_get_file_macosx_xulfiles(),
175 #'main.xul' => [$self->_get_file_macosx_mainxul()],
176 },
177 },
178 'defaults' => {
179 'preferences' => {
180 'prefs.js' => [$self->_get_file_macosx_prefs()],
181 },
182 },
183 'perl' => {
184 'server' => {
185 #'server.pl' => [$self->_get_file_macosx_serverpl()],
186 },
187 'modules' => {
188 'Eventhandlers.pm' => [$self->_get_file_macosx_eventhandlers()],
189 'App' => {
190 'XUL' => {
191 #'XML' => [],
192 #'Object' => [],
193 },
194 },
195 },
196 },
197 'extensions' => {},
198 'updates' => {
199 '0' => {},
200 },
201 },
202 }
203 }
204 );
205
206 # copy misc files into tmpdir
207 0 ▶ die "Error: no XUL.framework found in /Library/Frameworks - please install XUL framework from mozilla.org\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d "/Library/Frameworks/XUL.framework" 0 0 0
208 unless -d '/Library/Frameworks/XUL.framework';
209 0 dircopy('/Library/Frameworks/XUL.framework',
210 $tmpdir->base().'/'.$name.'.app/Contents/Frameworks/XUL.framework');
211
212 0 fcopy($utilspath.'/Appicon.icns',
213 $tmpdir->base().'/'.$name.'.app/Contents/Resources/'.$name.'.icns');
214  
215 0 fcopy($utilspath.'/AppXUL.js',
216 $tmpdir->base().'/'.$name.'.app/Contents/Resources/chrome/content/AppXUL.js');
217  
218 #fcopy('../../misc/AppXULServer.js',
219 # $tmpdir->base().'/'.$name.'.app/Contents/Resources/chrome/content/AppXULServer.js');
220  
221 0 fcopy($utilspath.'/server.pl',
222 $tmpdir->base().'/'.$name.'.app/Contents/Resources/perl/server/server.pl');
223  
224 0 fcopy($utilspath.'/../lib/App/XUL/XML.pm',
225 $tmpdir->base().'/'.$name.'.app/Contents/Resources/perl/modules/App/XUL/XML.pm');
226  
227 0 fcopy($utilspath.'/../lib/App/XUL/Object.pm',
228 $tmpdir->base().'/'.$name.'.app/Contents/Resources/perl/modules/App/XUL/Object.pm');
229  
230 # chmod certain files
231 0 chmod(0755, $tmpdir->base().'/'.$name.'.app/Contents/MacOS/start.pl');
232  
233 # move tmpdir to final destination
234 0 rename($tmpdir->base().'/'.$name.'.app', $path);
235 }
236 else {
237 0 die "Error: os '$os' not implemented yet\n";
238 }
239 }
240  
241 ################################################################################
242  
243 sub _get_file_macosx_eventhandlers
244 0 ▶{
Subroutine _get_file_macosx_eventhandlers: not called CC=2 SCAR=17.9
245 0 my ($self) = @_;
246 0 my $eventhandlers = '';
247 0 foreach my $name (keys %{$self->{'bindings'}}) {
248 0 $eventhandlers .= "'".$name."' => \n".Dumper($self->{'bindings'}->{$name}).",\n";
249 }
250 return
251 0 'package Eventhandlers;'."\n".
252 'use App::XUL::XML;'."\n".
253 '$App::XUL::XML::RunInsideServer = 1;'."\n".
254 'our $AUTOLOAD;'."\n".
255 'sub AUTOLOAD {'."\n".
256 ' $App::XUL::XML::AUTOLOAD = $AUTOLOAD;'."\n".
257 ' return App::XUL::XML::AUTOLOAD(@_);'."\n".
258 '}'."\n".
259 'sub get {'."\n".
260 ' return {'."\n".
261 $eventhandlers.
262 ' };'."\n".
263 '}'."\n".
264 '1;'."\n";
265 }
266  
267 sub _get_file_macosx_prefs
268 0 ▶{
Subroutine _get_file_macosx_prefs: not called CC=1 SCAR=6.9
269 0 my ($self) = @_;
270 return <<EOFSRC
271 pref("toolkit.defaultChromeURI", "chrome://$self->{'name'}/content/main.xul");
272  
273 /* debugging prefs */
274 pref("browser.dom.window.dump.enabled", true);
275 pref("javascript.options.showInConsole", true);
276 pref("javascript.options.strict", true);
277 pref("nglayout.debug.disable_xul_cache", true);
278 pref("nglayout.debug.disable_xul_fastload", true);
279 EOFSRC
280 0 }
281  
282 sub _get_file_macosx_xulfiles
283 0 ▶{
Subroutine _get_file_macosx_xulfiles: not called CC=3 SCAR=24.8
284 0 my ($self) = @_;
285 0 my @files = ();
286 0 my $w = 0;
287 0 foreach my $window_xml (@{$self->{'windows'}}) {
288 0 my $xml =
289 '<?xml version="1.0"?>'."\n".
290 '<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>'."\n".
291 $window_xml;
292 0 ▶ push @files, ($w == 0 ? 'main' : 'sub'.$w).'.xul', [$xml];
Branch: 1 branch
BranchTrueFalseTotal
$w == 0 ? : 0 0 0
293 0 $w++;
294 }
295 0 return @files;
296 # return
297 # '<?xml version="1.0"?>'."\n".
298 # '<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>'."\n".
299 # $self->{'xml'};
300 #<window id="mw" title="$self->{'name'}" width="800" height="200"
301 # xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
302 # xmlns:html="http://www.w3.org/1999/xhtml">
303 # <script src="AppXUL.js"/>
304 # ...
305 #</window>
306 }
307  
308 sub _get_file_macosx_chromemanifest
309 0 ▶{
Subroutine _get_file_macosx_chromemanifest: not called CC=1 SCAR=6.9
310 0 my ($self) = @_;
311 0 return 'content '.$self->{'name'}.' file:content/'."\n";
312 }
313  
314 sub _get_file_macosx_appini
315 0 ▶{
Subroutine _get_file_macosx_appini: not called CC=1 SCAR=6.9
316 0 my ($self) = @_;
317 return <<EOFSRC
318 [App]
319 Version=1.0
320 Vendor=Me
321 Name=$self->{'name'}
322 BuildID=myid
323 ID={generated id}
324  
325 [Gecko]
326 MinVersion=1.8
327 MaxVersion=2.*
328 EOFSRC
329 0 }
330  
331 sub _get_file_startpl
332 0 ▶{
Subroutine _get_file_startpl: not called CC=5 SCAR=34.0
333 0 my ($self, $os, $type) = @_;
334
335 0 ▶ if ($os eq 'chrome') {
Branch: 2 branches
BranchTrueFalseTotal
if ($os eq 'chrome') { } 0 0 0
elsif ($os eq 'macosx') { } 0 0 0
336 0 my $xulrunnerpath = {
337 macosx => '/Library/Frameworks/XUL.framework/xulrunner-bin',
338 win => 'c:\Program Files\xulrunner\xulrunner',
339 linux => 'xulrunner',
340 };
341 return
342 '#!/usr/bin/perl -w'."\n".
343 q{use strict;
344 use Cwd 'abs_path';
345 my $path = abs_path($0);
346 $path =~ s/\/start\_[a-z]+.pl$//;
347 system(
348 '"'.$path."/perl/server/server.pl".'" '.
349 '"'.$path."/perl/modules/".'" 3000 &'
350 );
351 exec(
352 "}.$xulrunnerpath->{$type}.q{",
353 "-app", $path."/application.ini",}.
354 0 ▶ ($self->{'debug'} ? '"-jsconsole"' : '').
Branch: 1 branch
BranchTrueFalseTotal
$self->{'debug'} ? : 0 0 0
355 ');'."\n";
356 }
357 elsif ($os eq 'macosx') {
358 return
359 '#!/usr/bin/perl -w'."\n".
360 q{use strict;
361 use Cwd 'abs_path';
362 my $path = abs_path($0);
363 $path =~ s/\/MacOS\/[^\/]+//;
364 system(
365 '"'.$path."/Resources/perl/server/server.pl".'" '.
366 '"'.$path."/Resources/perl/modules/".'" 3000 &'
367 );
368 exec(
369 $path."/Frameworks/XUL.framework/xulrunner-bin",
370 "-app", $path."/Resources/application.ini",}.
371 0 ▶ ($self->{'debug'} ? '"-jsconsole"' : '').
Branch: 1 branch
BranchTrueFalseTotal
$self->{'debug'} ? : 0 0 0
372 ');'."\n";
373 }
374 else {
375 0 return '';
376 }
377 }
378  
379 sub _get_file_maxosx_infoplist
380 0 ▶{
Subroutine _get_file_maxosx_infoplist: not called CC=1 SCAR=6.9
381 0 my ($self) = @_;
382 return <<EOFSRC
383 <?xml version="1.0" encoding="UTF-8"?>
384 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
385 <plist version="1.0">
386 <dict>
387 <key>CFBundleDevelopmentRegion</key>
388 <string>English</string>
389 <key>CFBundleExecutable</key>
390 <string>start.pl</string>
391 <key>CFBundleGetInfoString</key>
392 <string>XULExplorer 1.0a1pre, © 2007-2008 Contributors</string>
393 <key>CFBundleIconFile</key>
394 <string>$self->{'name'}</string>
395 <key>CFBundleIdentifier</key>
396 <string>org.mozilla.mccoy</string>
397 <key>CFBundleInfoDictionaryVersion</key>
398 <string>6.0</string>
399 <key>CFBundleName</key>
400 <string>$self->{'name'}</string>
401 <key>CFBundlePackageType</key>
402 <string>APPL</string>
403 <key>CFBundleShortVersionString</key>
404 <string>1.0a1pre</string>
405 <key>CFBundleSignature</key>
406 <string>MOZB</string>
407 <key>CFBundleVersion</key>
408 <string>1.0a1pre</string>
409 <key>NSAppleScriptEnabled</key>
410 <true/>
411 </dict>
412 </plist>
413 EOFSRC
414 0 }
415  
416 1 1;
417 __END__
« XUL/Object.pm ↑ Summary