line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XUL::App::XULFile; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2156
|
use lib 'lib'; |
|
1
|
|
|
|
|
629
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
104
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
4
|
use File::Slurp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
61
|
|
7
|
1
|
|
|
1
|
|
1045
|
use Encode; |
|
1
|
|
|
|
|
12306
|
|
|
1
|
|
|
|
|
127
|
|
8
|
|
|
|
|
|
|
#use Smart::Comments; |
9
|
1
|
|
|
1
|
|
7
|
use XUL::App; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
10
|
1
|
|
|
1
|
|
716
|
use File::ShareDir (); |
|
1
|
|
|
|
|
6076
|
|
|
1
|
|
|
|
|
30
|
|
11
|
1
|
|
|
1
|
|
1147
|
use File::Copy (); |
|
1
|
|
|
|
|
2153
|
|
|
1
|
|
|
|
|
21
|
|
12
|
1
|
|
|
1
|
|
6
|
use File::Basename 'dirname'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
85
|
|
13
|
|
|
|
|
|
|
#use File::Path (); |
14
|
1
|
|
|
1
|
|
852
|
use File::Copy::Recursive (); |
|
1
|
|
|
|
|
4047
|
|
|
1
|
|
|
|
|
26
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
9
|
use base 'Class::Accessor::Fast'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1570
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw{ |
18
|
|
|
|
|
|
|
name generated_from prereqs overlays |
19
|
|
|
|
|
|
|
}); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
23
|
0
|
|
|
|
|
|
my $self = $proto->SUPER::new(@_); |
24
|
0
|
|
|
|
|
|
my $src = $self->generated_from; |
25
|
0
|
|
|
|
|
|
my ($module, $opts); |
26
|
0
|
0
|
|
|
|
|
if (ref $src eq 'HASH') { |
|
|
0
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
($module, $opts) = %$src; |
28
|
|
|
|
|
|
|
} elsif (ref $src) { |
29
|
0
|
|
|
|
|
|
($module, $opts) = @$src; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
$module = $src; |
32
|
0
|
|
|
|
|
|
$opts = {}; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
$self->{module} = $module; |
35
|
0
|
|
0
|
|
|
|
$self->{template} = delete $opts->{template} || 'main'; |
36
|
0
|
|
0
|
|
|
|
my $args = delete $opts->{arguments} || []; |
37
|
0
|
0
|
|
|
|
|
if (ref $args ne 'ARRAY') { $args = [$args]; } |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->{args} = $args; |
39
|
0
|
0
|
|
|
|
|
if (%$opts) { |
40
|
0
|
|
|
|
|
|
die "Unknown option for view class $self->{template}: ", join(" ", keys %$opts); |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub go { |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
47
|
0
|
|
|
|
|
|
my $module = $self->{module}; |
48
|
0
|
|
|
|
|
|
my $args = $self->{args}; |
49
|
0
|
|
|
|
|
|
my $template = $self->{template}; |
50
|
0
|
|
|
|
|
|
eval "use $module;"; |
51
|
0
|
0
|
|
|
|
|
if ($@) { |
52
|
0
|
|
|
|
|
|
warn $@; |
53
|
0
|
|
|
|
|
|
die "Can't load $module due to compilation errors.\n"; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
Template::Declare->init(roots => [$module]); |
56
|
|
|
|
|
|
|
# XXX $opts->{template}, $opts->{arguments} |
57
|
0
|
0
|
|
|
|
|
mkdir 'tmp' if !-d 'tmp'; |
58
|
0
|
0
|
|
|
|
|
mkdir 'tmp/content' if !-d 'tmp/content'; |
59
|
0
|
|
|
|
|
|
my @all_prereqs = find_all_prereqs($file); |
60
|
|
|
|
|
|
|
### @all_prereqs |
61
|
0
|
|
|
|
|
|
my $xml = Template::Declare->show($template, @$args); |
62
|
0
|
|
|
|
|
|
my (@jsfiles, @cssfiles); |
63
|
0
|
|
|
|
|
|
for my $file (@all_prereqs) { |
64
|
0
|
0
|
|
|
|
|
if ($file =~ /\.js$/i) { |
65
|
0
|
|
|
|
|
|
push @jsfiles, $file; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
push @cssfiles, $file; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
my $last_tag_pat = qr{ [^>]+ > \s* $}xs; |
71
|
0
|
|
|
|
|
|
for my $file (@jsfiles) { |
72
|
0
|
0
|
|
|
|
|
if ($file !~ /^\w+:\/\//) { |
73
|
0
|
|
|
|
|
|
check_js_file($file); |
74
|
0
|
|
|
|
|
|
$file = "chrome://$XUL::App::APP_NAME/content/$file"; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
$xml =~ s{$last_tag_pat}{\n$&}; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
my $first_tag_pat = qr{ .* <\? [^>]+ \?> }xs; |
79
|
0
|
|
|
|
|
|
for my $file (reverse @cssfiles) { |
80
|
0
|
0
|
|
|
|
|
if ($file !~ /^\w+:\/\//) { |
81
|
0
|
|
|
|
|
|
check_css_file($file); |
82
|
0
|
|
|
|
|
|
$file = "chrome://$XUL::App::APP_NAME/content/$file"; |
83
|
|
|
|
|
|
|
} |
84
|
0
|
|
|
|
|
|
$xml =~ s{$first_tag_pat}{$&\n}; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
my $path = "tmp/content/$file"; |
87
|
0
|
|
|
|
|
|
warn "Writing file $path\n"; |
88
|
0
|
|
|
|
|
|
$xml = encode('UTF-8', $xml); |
89
|
0
|
|
|
|
|
|
write_file( |
90
|
|
|
|
|
|
|
$path, |
91
|
|
|
|
|
|
|
{binmode => ':raw'}, |
92
|
|
|
|
|
|
|
$xml |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub find_all_prereqs { |
97
|
0
|
|
|
0
|
0
|
|
my ($file, $visited) = @_; |
98
|
0
|
|
0
|
|
|
|
$visited ||= {}; |
99
|
0
|
0
|
|
|
|
|
if ($visited->{$file}) { return () }; |
|
0
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$visited->{$file} = 1; |
101
|
|
|
|
|
|
|
## File: $file |
102
|
0
|
|
|
|
|
|
my $obj = XUL::App->FILES->{$file}; |
103
|
|
|
|
|
|
|
## Obj: $obj |
104
|
0
|
0
|
|
|
|
|
return () unless $obj; |
105
|
0
|
|
|
|
|
|
my $prereqs = $obj->prereqs; |
106
|
|
|
|
|
|
|
## $prereqs |
107
|
0
|
0
|
0
|
|
|
|
if ($prereqs and !ref $prereqs) { $prereqs = [$prereqs]; } |
|
0
|
|
|
|
|
|
|
108
|
0
|
0
|
0
|
|
|
|
if ($prereqs and @$prereqs) { |
109
|
0
|
|
|
|
|
|
return map { |
110
|
0
|
|
|
|
|
|
find_all_prereqs($_, $visited), $_ |
111
|
|
|
|
|
|
|
} @$prereqs; |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
return (); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub copy_file { |
117
|
0
|
|
|
0
|
0
|
|
my ($from, $to) = @_; |
118
|
0
|
|
|
|
|
|
print "cp $from $to\n"; |
119
|
0
|
|
|
|
|
|
File::Copy::Recursive::fcopy($from, $to); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub copy_dir { |
123
|
0
|
|
|
0
|
0
|
|
my ($from, $to) = @_; |
124
|
0
|
|
|
|
|
|
print "cp -r $from $to\n"; |
125
|
0
|
|
|
|
|
|
File::Copy::Recursive::dircopy($from, $to); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub check_js_file { |
129
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
130
|
0
|
0
|
0
|
|
|
|
if (!-f "js/$file" and !-f "js/thirdparty/$file" and !-f "tmp/content/$file") { |
131
|
0
|
|
|
|
|
|
my $share_dir = File::ShareDir::module_dir('XUL::App'); |
132
|
|
|
|
|
|
|
#warn $share_dir; |
133
|
0
|
|
|
|
|
|
my $default_js = "$share_dir/js/$file"; |
134
|
|
|
|
|
|
|
#warn $share_dir; |
135
|
0
|
0
|
|
|
|
|
if (-f $default_js) { |
136
|
0
|
|
|
|
|
|
my $dir = dirname($file); |
137
|
0
|
0
|
|
|
|
|
if ($dir =~ /jslib(\S*)/) { |
138
|
0
|
|
|
|
|
|
my $subdir = $1; |
139
|
|
|
|
|
|
|
#mkdir('tmp/content/jslib'); |
140
|
0
|
|
|
|
|
|
my $outfile = "tmp/content/jslib/jslib.js"; |
141
|
0
|
0
|
|
|
|
|
copy_file("$share_dir/js/jslib/jslib.js", $outfile) unless -f $outfile; |
142
|
0
|
|
|
|
|
|
fix_jslib_js($outfile); |
143
|
0
|
|
|
|
|
|
$outfile = "tmp/content/jslib/modules.js"; |
144
|
0
|
0
|
|
|
|
|
copy_file("$share_dir/js/jslib/modules.js", $outfile) unless -f $outfile; |
145
|
0
|
|
|
|
|
|
my $outdir = "tmp/content/jslib/debug"; |
146
|
0
|
0
|
|
|
|
|
copy_dir("$share_dir/js/jslib/debug", $outdir) unless -d $outdir; |
147
|
0
|
0
|
|
|
|
|
if ($subdir) { |
148
|
0
|
|
|
|
|
|
copy_dir("$share_dir/js/$dir", "tmp/content/$dir"); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} else { |
151
|
0
|
|
|
|
|
|
print "cp $default_js tmp/content/\n"; |
152
|
0
|
|
|
|
|
|
File::Copy::copy($default_js, "tmp/content/$file"); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} else { |
155
|
0
|
|
|
|
|
|
die "Can't find JavaScript file $file in either js/ or js/thirdparty/\n"; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub fix_jslib_js { |
161
|
0
|
|
|
0
|
0
|
|
my $path = shift; |
162
|
0
|
|
|
|
|
|
my $content = read_file($path); |
163
|
0
|
|
|
|
|
|
$content =~ s{\bchrome://jslib/content/}{chrome://$XUL::App::APP_NAME/content/}g; |
164
|
0
|
|
|
|
|
|
chmod(0644, $path); |
165
|
0
|
|
|
|
|
|
write_file($path, $content); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub check_css_file { |
169
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
170
|
0
|
0
|
|
|
|
|
if (!-f "css/$file") { |
171
|
0
|
|
|
|
|
|
die "Can't find CSS file $file in either js/ or js/thirdparty/\n"; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |