1 |
package WebHACC::Language::CacheManifest; |
2 |
use strict; |
3 |
require WebHACC::Language::Base; |
4 |
push our @ISA, 'WebHACC::Language::Base'; |
5 |
|
6 |
sub new ($) { |
7 |
my $self = bless {}, shift; |
8 |
return $self; |
9 |
} # new |
10 |
|
11 |
sub generate_syntax_error_section ($) { |
12 |
my $self = shift; |
13 |
|
14 |
require Whatpm::CacheManifest; |
15 |
|
16 |
my $out = $self->output; |
17 |
|
18 |
$self->result->layer_uncertain ('charset'); |
19 |
|
20 |
$out->start_section (role => 'parse-errors'); |
21 |
$out->start_error_list (role => 'parse-errors'); |
22 |
$self->result->layer_applicable ('syntax'); |
23 |
|
24 |
my $input = $self->input; |
25 |
my $result = $self->result; |
26 |
|
27 |
$self->result->layer_uncertain ('encode') unless $input->{is_char_string}; |
28 |
|
29 |
my $m = $input->{is_char_string} ? 'parse_char_string' : 'parse_byte_string'; |
30 |
$self->{structure} = Whatpm::CacheManifest->$m |
31 |
($input->{s}, $input->url, $input->{base_uri}, sub { |
32 |
$result->add_error (@_, layer => 'syntax', index_has_link => 1); |
33 |
}); |
34 |
|
35 |
$out->end_error_list (role => 'parse-errors'); |
36 |
$out->end_section; |
37 |
} # generate_syntax_error_section |
38 |
|
39 |
sub generate_structure_dump_section ($) { |
40 |
my $self = shift; |
41 |
my $manifest = $self->{structure} || [[], {}, []]; # undef if it is not a manifest. |
42 |
|
43 |
my $out = $self->output; |
44 |
|
45 |
$out->start_section (role => 'structure'); |
46 |
|
47 |
$out->start_tag ('dl'); |
48 |
my $i = 0; |
49 |
|
50 |
$out->start_tag ('dt'); |
51 |
$out->nl_text ('Explicit entries'); |
52 |
if (@{$manifest->[0]}) { |
53 |
for my $uri (@{$manifest->[0]}) { |
54 |
$out->start_tag ('dd', id => 'index-' . $i++); |
55 |
$out->url ($uri); |
56 |
} |
57 |
} else { |
58 |
$out->start_tag ('dd', class => 'no-entry'); |
59 |
$out->nl_text ('No entry'); |
60 |
} |
61 |
|
62 |
$out->start_tag ('dt'); |
63 |
$out->nl_text ('Fallback entries'); |
64 |
if (keys %{$manifest->[1]}) { |
65 |
$out->start_tag ('dd', class => 'manifest-fallbacks'); |
66 |
for my $uri (sort {$a cmp $b} keys %{$manifest->[1]}) { |
67 |
$out->start_tag ('p', id => 'index-' . $i++); |
68 |
$out->nl_text ('Opportunistic caching namespace'); |
69 |
$out->text (': '); |
70 |
$out->url ($uri); |
71 |
|
72 |
$out->start_tag ('p', id => 'index-' . $i++); |
73 |
$out->nl_text ('Fallback entry'); |
74 |
$out->text (': '); |
75 |
$out->url ($manifest->[1]->{$uri}); |
76 |
} |
77 |
} else { |
78 |
$out->start_tag ('dd', class => 'no-entry'); |
79 |
$out->nl_text ('No entry'); |
80 |
} |
81 |
|
82 |
$out->start_tag ('dt'); |
83 |
$out->nl_text ('Online whitelist'); |
84 |
if (@{$manifest->[2]}) { |
85 |
for my $uri (@{$manifest->[2]}) { |
86 |
$out->start_tag ('dd', id => 'index-' . $i++); |
87 |
$out->url ($uri); |
88 |
} |
89 |
} else { |
90 |
$out->start_tag ('dd', class => 'no-entry'); |
91 |
$out->nl_text ('No entry'); |
92 |
} |
93 |
|
94 |
$out->end_tag ('dl'); |
95 |
|
96 |
$out->end_section; |
97 |
} # generate_structure_dump_section |
98 |
|
99 |
sub generate_structure_error_section ($) { |
100 |
my $self = shift; |
101 |
|
102 |
my $out = $self->output; |
103 |
|
104 |
$out->start_section (role => 'structure-errors'); |
105 |
$out->start_error_list (role => 'structure-errors'); |
106 |
$self->result->layer_applicable ('structure'); |
107 |
|
108 |
my $result = $self->result; |
109 |
|
110 |
Whatpm::CacheManifest->check_manifest ($self->{structure}, sub { |
111 |
$result->add_error (@_, layer => 'structure'); |
112 |
}); |
113 |
|
114 |
$out->end_error_list; |
115 |
$out->end_section; |
116 |
} # generate_structure_error_section |
117 |
|
118 |
sub source_charset ($) { |
119 |
return 'utf-8'; |
120 |
} # source_charset |
121 |
|
122 |
1; |