| 1 | package App::DuckPAN::Cmd::Server; | ||||||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:DDG'; | |||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Starting up the web server to test instant answers | ||||||||||||||||||||||||||||||||
| 4 | 1 | $App::DuckPAN::Cmd::Server::VERSION = '1021'; | |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | with qw( App::DuckPAN::Cmd App::DuckPAN::Restart ); | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Options protect_argv => 0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::Runner; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::ShareDir::ProjectDistDir; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use LWP::Simple; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use HTML::TreeBuilder; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Config::INI; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Term::ProgressBar; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | option port => ( | ||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 20 | format => 'i', | ||||||||||||||||||||||||||||||||
| 21 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 22 | short => 'p', | ||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | default => sub { 5000 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 24 | 1 | doc => 'set port on which server should listen. defaults to 5000', | |||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 1 | has page_info => ( | |||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 29 | builder => '_build_page_info', | ||||||||||||||||||||||||||||||||
| 30 | lazy=> 1, | ||||||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub _build_page_info { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_page_info: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 35 | 0 | my $cache_path = $self->asset_cache_path; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | return +{ | ||||||||||||||||||||||||||||||||
| 38 | 0 | js => [], | |||||||||||||||||||||||||||||||
| 39 | locales => [], | ||||||||||||||||||||||||||||||||
| 40 | css => [], | ||||||||||||||||||||||||||||||||
| 41 | templates => [{ | ||||||||||||||||||||||||||||||||
| 42 | name => 'Template Compiling JS', | ||||||||||||||||||||||||||||||||
| 43 | internal => $cache_path->child('template_compiler.js'), | ||||||||||||||||||||||||||||||||
| 44 | # stored locally, no need to make web request for this | ||||||||||||||||||||||||||||||||
| 45 | external => undef, | ||||||||||||||||||||||||||||||||
| 46 | desc => 'Small script DuckPAN runs on SERP load; compiles Spice IA templates', | ||||||||||||||||||||||||||||||||
| 47 | }, | ||||||||||||||||||||||||||||||||
| 48 | ], | ||||||||||||||||||||||||||||||||
| 49 | root => [{ | ||||||||||||||||||||||||||||||||
| 50 | name => 'DDG Homepage', | ||||||||||||||||||||||||||||||||
| 51 | internal => $cache_path->child('page_root.html'), | ||||||||||||||||||||||||||||||||
| 52 | external => '/', | ||||||||||||||||||||||||||||||||
| 53 | desc => 'used for error page when no instant answers trigger', | ||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||||||
| 56 | spice => [{ | ||||||||||||||||||||||||||||||||
| 57 | name => 'DDG SERP', | ||||||||||||||||||||||||||||||||
| 58 | internal => $cache_path->child('page_spice.html'), | ||||||||||||||||||||||||||||||||
| 59 | external => '/?q=duckduckhack-template-for-spice2', | ||||||||||||||||||||||||||||||||
| 60 | load_sub_assets => 1, | ||||||||||||||||||||||||||||||||
| 61 | desc => 'this is the page we inject Spice and Goodie results into', | ||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||
| 63 | ], | ||||||||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 1 | has hostname => ( | |||||||||||||||||||||||||||||||
| 68 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 69 | builder => '_build_hostname', | ||||||||||||||||||||||||||||||||
| 70 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _build_hostname { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_hostname: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 74 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 75 | 0 | return $self->app->server_hostname; | |||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 1 | has asset_cache_path => ( | |||||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 80 | builder => 1, | ||||||||||||||||||||||||||||||||
| 81 | lazy => 1, | ||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub _build_asset_cache_path { | ||||||||||||||||||||||||||||||
|
Subroutine
_build_asset_cache_path: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 85 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | my $asset_path = $self->app->cfg->cache_path->child($self->hostname); | |||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $asset_path->mkpath unless $asset_path->exists; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 0 | return $asset_path; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | # Entry point into app | ||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 95 | 0 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | $self->run_restarter(\@args); | |||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | # Starts the Plack server on the designated port. Will be launched in a child | ||||||||||||||||||||||||||||||||
| 101 | # process since it blocks. Will be killed by user ctrl-c or parent explicitly | ||||||||||||||||||||||||||||||||
| 102 | # kill'ing it. | ||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub _run_app { | ||||||||||||||||||||||||||||||
|
Subroutine
_run_app: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 0 | my $cache_path = $self->app->cfg->cache_path; | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 0 | $self->app->check_requirements; # Ensure eveything is up do date, or exit. | |||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 0 | my @blocks = @{$self->app->ddg->get_blocks_from_current_dir(@$args)}; | |||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | 0 | $self->app->emit_debug("Hostname is: https://" . $self->hostname); | |||||||||||||||||||||||||||||||
| 113 | 0 | $self->app->emit_info("Checking asset cache..."); | |||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 0 | foreach my $asset (map { @{$self->page_info->{$_}} } (qw(root spice templates))) { | |||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if (defined $asset->{external}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | $self->retrieve_and_cache($asset); | |||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | else { | ||||||||||||||||||||||||||||||||
| 120 | # Files without external sources should be copied from the distribution. | ||||||||||||||||||||||||||||||||
| 121 | 0 | my $to_file = $asset->{internal}; | |||||||||||||||||||||||||||||||
| 122 | 0 | my $from_file = path(dist_dir('App-DuckPAN'), $to_file->basename); | |||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $from_file->copy($to_file) if ($from_file->exists && !$to_file->exists); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$from_file->exists and not $to_file->exists
MC/DC0%0/2
$from_file->exists and not $to_file->exists
$from_file->exists
not $to_file->exists
Truth table0%0/3
A and not(B)
A= $from_file->existsB= not $to_file->exists
| |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | # Pull files out of cache to be served later by DuckPAN server | ||||||||||||||||||||||||||||||||
| 128 | 0 | my %web_args = ( | |||||||||||||||||||||||||||||||
| 129 | blocks => \@blocks, | ||||||||||||||||||||||||||||||||
| 130 | server_hostname => $self->hostname | ||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||
| 132 | 0 | foreach my $page (keys %{$self->page_info}) { | |||||||||||||||||||||||||||||||
| 133 | 0 | $web_args{'page_' . $page} = $self->slurp_or_empty($self->page_info->{$page}); | |||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 0 | $self->app->emit_info("Starting up webserver...", "You can stop the webserver with Ctrl-C"); | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 0 | require App::DuckPAN::Web; | |||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 0 | my $web = App::DuckPAN::Web->new(%web_args); | |||||||||||||||||||||||||||||||
| 141 | my $runner = Plack::Runner->new( | ||||||||||||||||||||||||||||||||
| 142 | #loader => 'Restarter', | ||||||||||||||||||||||||||||||||
| 143 | includes => ['lib'], | ||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | app => sub { $web->run_psgi($self->app, @_) }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 145 | 0 | ); | |||||||||||||||||||||||||||||||
| 146 | #$runner->loader->watch("./lib"); | ||||||||||||||||||||||||||||||||
| 147 | 0 | $runner->parse_options("--port", $self->port); | |||||||||||||||||||||||||||||||
| 148 | 0 | exit $runner->run; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub slurp_or_empty { | ||||||||||||||||||||||||||||||
|
Subroutine
slurp_or_empty: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 152 | 0 | my ($self, $which) = @_; | |||||||||||||||||||||||||||||||
| 153 | 0 | my $cache_path = $self->asset_cache_path; | |||||||||||||||||||||||||||||||
| 154 | 0 | my $contents = ''; | |||||||||||||||||||||||||||||||
| 155 | 0 | foreach my $which_file (grep { $_->{internal} } (@$which)) { | |||||||||||||||||||||||||||||||
| 156 | 0 | my $where = $which_file->{internal}; | |||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my $change_method = ($where =~ m/\.js$/) ? 'change_js' : ($where =~ m/\.css$/) ? 'change_css' : 'change_html'; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $contents .= $self->make_source_comment($which_file) . $self->$change_method($where->slurp) if ($where->exists); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||
| 162 | 0 | return $contents; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub make_source_comment { | ||||||||||||||||||||||||||||||
|
Subroutine
make_source_comment: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 166 | 0 | my ($self, $file_info) = @_; | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 0 | my $comment = ''; | |||||||||||||||||||||||||||||||
| 169 | 0 | my $internal = $file_info->{internal}; | |||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $title = $file_info->{name} || $internal; | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$file_info->{'name'} || $internal
MC/DC0%0/2
$file_info->{'name'} || $internal
$file_info->{'name'}
$internal
Truth table0%0/3
A || B
A= $file_info->{'name'}B= $internal
| |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ($internal =~ /js$/) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 172 | 0 | $comment = '// ' . $title; | |||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||
| 174 | elsif ($internal =~ /css$/) { | ||||||||||||||||||||||||||||||||
| 175 | 0 | $comment = '/* ' . $title . '*/'; | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | elsif ($internal =~ /html$/) { | ||||||||||||||||||||||||||||||||
| 178 | 0 | $comment = '<!-- ' . $title . ' -->'; | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||
| 181 | 0 | return "\n$comment\n"; # Just two blank lines if we don't know how to comment for the file type. | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | # Force DuckPAN to ignore requests for certain files | ||||||||||||||||||||||||||||||||
| 185 | # that are not needed (ie. d.js, s.js, g.js, post2.html) | ||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub change_js { | ||||||||||||||||||||||||||||||
|
Subroutine
change_js: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 187 | 0 | my ( $self, $js ) = @_; | |||||||||||||||||||||||||||||||
| 188 | 0 | $js =~ s!/([dsg]\d+?|duckduck|duckgo_dev)\.js\?!/?duckduckhack_ignore=1&!g; | |||||||||||||||||||||||||||||||
| 189 | 0 | $js =~ s!/post2\.html!/?duckduckhack_ignore=1&!g; | |||||||||||||||||||||||||||||||
| 190 | 0 | return $self->change_css($js); | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||
| 193 | # Rewrite all relative asset links in CSS | ||||||||||||||||||||||||||||||||
| 194 | # Capture leading quote, insert $hostname, append filename | ||||||||||||||||||||||||||||||||
| 195 | # E.g url("/assets/background.png") => url("http://duckduckgo.com/assets/background.png") | ||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub change_css { | ||||||||||||||||||||||||||||||
|
Subroutine
change_css: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 197 | 0 | my ( $self, $css ) = @_; | |||||||||||||||||||||||||||||||
| 198 | 0 | my $hostname = $self->hostname; | |||||||||||||||||||||||||||||||
| 199 | 0 | $css =~ s!:\s*url\((["'])?/!:url\($1http://$hostname/!g; | |||||||||||||||||||||||||||||||
| 200 | 0 | return $css; | |||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub change_html { | ||||||||||||||||||||||||||||||
|
Subroutine
change_html: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 204 | 0 | my ( $self, $html ) = @_; | |||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 0 | my $root = HTML::TreeBuilder->new; | |||||||||||||||||||||||||||||||
| 207 | 0 | $root->parse($html); | |||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 0 | my @a = $root->look_down( | |||||||||||||||||||||||||||||||
| 210 | "_tag", "a" | ||||||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | 0 | my @link = $root->look_down( | |||||||||||||||||||||||||||||||
| 214 | "_tag", "link" | ||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | # Make sure DuckPAN serves DDG CSS (already pulled down at startup) | ||||||||||||||||||||||||||||||||
| 218 | # ie <link href="/s123.css"> becomes <link href="/?duckduckhack_css=1"> | ||||||||||||||||||||||||||||||||
| 219 | # Also rewrite relative links to hostname | ||||||||||||||||||||||||||||||||
| 220 | 0 | my $has_css = 0; | |||||||||||||||||||||||||||||||
| 221 | 0 | for (@a, @link) { | |||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($_->attr('type') && $_->attr('type') eq 'text/css') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$_->attr("type") and $_->attr("type") eq "text/css"
MC/DC0%0/2
$_->attr("type") and $_->attr("type") eq "text/css"
$_->attr("type")
$_->attr("type") eq "text/css"
Truth table0%0/3
A and B
A= $_->attr("type")B= $_->attr("type") eq "text/css"
| |||||||||||||||||||||||||||||||||
| 223 | # We only want to load the CSS file once. | ||||||||||||||||||||||||||||||||
| 224 | # We only load it once because /?duckduckhack_css=1 already has all of the CSS | ||||||||||||||||||||||||||||||||
| 225 | # in a single page. | ||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | unless($has_css) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 227 | 0 | $_->attr('href','/?duckduckhack_css=1'); | |||||||||||||||||||||||||||||||
| 228 | 0 | $has_css = 1; | |||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | else { | ||||||||||||||||||||||||||||||||
| 231 | 0 | $_->attr('href','/?duckduckhack_ignore=1'); | |||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | ▶ | elsif (defined $_->attr('href') && substr($_->attr('href'),0,1) eq '/') { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->attr("href") and substr($_->attr("href"), 0, 1) eq "/"
MC/DC0%0/2
defined $_->attr("href") and substr($_->attr("href"), 0, 1) eq "/"
defined $_->attr("href")
substr($_->attr("href"), 0, 1) eq "/"
Truth table0%0/3
A and B
A= defined $_->attr("href")B= substr($_->attr("href"), 0, 1) eq "/"
| |||||||||||||||||||||||||||||||||
| 235 | 0 | $_->attr('href','http://'.$self->hostname.''.$_->attr('href')); | |||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | 0 | my @script = $root->look_down( | |||||||||||||||||||||||||||||||
| 240 | "_tag", "script" | ||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | # Make sure DuckPAN serves DDG JS (already pulled down at startup) | ||||||||||||||||||||||||||||||||
| 244 | # ie <link href="/d123.js"> becomes <link href="/?duckduckhack_js=1"> | ||||||||||||||||||||||||||||||||
| 245 | # Also rewrite relative links to hostname | ||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||
| 247 | # Temp Fix: Force ignore of d.js & duckduck. | ||||||||||||||||||||||||||||||||
| 248 | # This logic needs to be improved! | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 0 | my $has_ddh = 0; | |||||||||||||||||||||||||||||||
| 251 | 0 | for (@script) { | |||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (my $src = $_->attr('src')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | next if ($src =~ m/^\/\?duckduckhack_/); # Already updated, no need to do again | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ($src =~ m/^\/(dpan\d+|duckpan)\.js/) { | ||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($has_ddh){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | 0 | $_->attr('src','/?duckduckhack_ignore=1'); | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||
| 259 | 0 | $_->attr('src','/?duckduckhack_js=1'); | |||||||||||||||||||||||||||||||
| 260 | 0 | $has_ddh = 1; | |||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | elsif ($src =~ m/^\/(g\d+|serp)\.js/) { | ||||||||||||||||||||||||||||||||
| 264 | 0 | $_->attr('src','/?duckduckhack_templates=1'); | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | elsif ($src =~ m/^\/(d\d+|base)\.js/) { | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | # If dpan.js is not present (ie. homepage) | ||||||||||||||||||||||||||||||||
| 269 | # make sure we serve the js rather than blocking | ||||||||||||||||||||||||||||||||
| 270 | # the call to d.js | ||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ($has_ddh){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 272 | 0 | $_->attr('src','/?duckduckhack_ignore=1'); | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||
| 275 | 0 | $_->attr('src','/?duckduckhack_js=1'); | |||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||
| 278 | elsif ($src =~ /locales/) { | ||||||||||||||||||||||||||||||||
| 279 | 0 | $_->attr('src','/?duckduckhack_locales=1'); | |||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||
| 281 | elsif (substr($src,0,1) eq '/') { | ||||||||||||||||||||||||||||||||
| 282 | 0 | $_->attr('src','http://'.$self->hostname.''.$_->attr('src')); | |||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 0 | my @img = $root->look_down( | |||||||||||||||||||||||||||||||
| 288 | "_tag", "img" | ||||||||||||||||||||||||||||||||
| 289 | ); | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | # Rewrite img links to be requested from hostname | ||||||||||||||||||||||||||||||||
| 292 | 0 | for (@img) { | |||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($_->attr('src')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 294 | 0 | $_->attr('src','http://'.$self->hostname.''.$_->attr('src')); | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | 0 | my $newhtml = $root->as_HTML; | |||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||
| 300 | 0 | return $self->change_js($self->change_css($newhtml)); | |||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||
| 303 | # This is where we cache and check for newer versions | ||||||||||||||||||||||||||||||||
| 304 | # of DDG JS and CSS by parsing the HTML requested from | ||||||||||||||||||||||||||||||||
| 305 | # DuckDuckGo. If new files exits, we grab them, rewrite | ||||||||||||||||||||||||||||||||
| 306 | # any links and store them in the cache. Otherwise we | ||||||||||||||||||||||||||||||||
| 307 | # serve the current versions from the cache. | ||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub get_sub_assets { | ||||||||||||||||||||||||||||||
|
Subroutine
get_sub_assets: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 310 | 0 | my ($self, $from) = @_; | |||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | 0 | my $html = $from->{internal}->slurp; | |||||||||||||||||||||||||||||||
| 313 | 0 | my $root = HTML::TreeBuilder->new; | |||||||||||||||||||||||||||||||
| 314 | 0 | $root->parse($html); | |||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 0 | my @script = $root->look_down( | |||||||||||||||||||||||||||||||
| 317 | "_tag", "script" | ||||||||||||||||||||||||||||||||
| 318 | ); | ||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 0 | my @link = $root->look_down( | |||||||||||||||||||||||||||||||
| 321 | "_tag", "link" | ||||||||||||||||||||||||||||||||
| 322 | ); | ||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||
| 324 | 0 | my $cache_path = $self->asset_cache_path; | |||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||
| 326 | # Find version no. for d.js and g.js | ||||||||||||||||||||||||||||||||
| 327 | 0 | for (@script) { | |||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if (my $src = $_->attr('src')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ($src =~ m/^\/((?:dpan\d+|duckpan)\.js)/) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 330 | 0 | unshift @{$self->page_info->{js}}, | |||||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||||||
| 332 | name => 'Main JS', | ||||||||||||||||||||||||||||||||
| 333 | internal => $cache_path->child($1), | ||||||||||||||||||||||||||||||||
| 334 | external => $1 | ||||||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | elsif ($src =~ m/^\/((?:g\d+|serp)\.js)/) { | ||||||||||||||||||||||||||||||||
| 338 | 0 | unshift @{$self->page_info->{templates}}, | |||||||||||||||||||||||||||||||
| 339 | { | ||||||||||||||||||||||||||||||||
| 340 | name => 'Templating JS', | ||||||||||||||||||||||||||||||||
| 341 | internal => $cache_path->child($1), | ||||||||||||||||||||||||||||||||
| 342 | external => $1 | ||||||||||||||||||||||||||||||||
| 343 | }; | ||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | elsif ($src =~ m/^\/(locales(?:.*)\.js)/) { | ||||||||||||||||||||||||||||||||
| 346 | 0 | my $long_path = $1; | |||||||||||||||||||||||||||||||
| 347 | 0 | my $cache_name = $long_path; | |||||||||||||||||||||||||||||||
| 348 | 0 | $cache_name =~ s#^.+(\.\d+\.\d+\.js)#locales$1#g; # Turn long path into cacheable name | |||||||||||||||||||||||||||||||
| 349 | 0 | unshift @{$self->page_info->{locales}}, | |||||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||||||
| 351 | name => 'Locales JS', | ||||||||||||||||||||||||||||||||
| 352 | internal => $cache_path->child($cache_name), | ||||||||||||||||||||||||||||||||
| 353 | external => $long_path | ||||||||||||||||||||||||||||||||
| 354 | }; | ||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | 0 | my @cssfile; | |||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | for (grep { $_->attr('type') && $_->attr('type') eq 'text/css' } @link) { | ||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->attr('type') && $_->attr('type') eq 'text/css'
MC/DC0%0/2
$_->attr('type') && $_->attr('type') eq 'text/css'
$_->attr('type')
$_->attr('type') eq 'text/css'
Truth table0%0/3
A && B
A= $_->attr('type')B= $_->attr('type') eq 'text/css'
| |||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if (my $href = $_->attr('href')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | # We're looking for txxx.css and sxxx.css. | ||||||||||||||||||||||||||||||||
| 363 | # style.css and static.css are for development mode. | ||||||||||||||||||||||||||||||||
| 364 | 0 | ▶ | if ($href =~ m/^\/((?:[str]\d+|style|static|serp)\.css)/) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 365 | 0 | my $name = $1; | |||||||||||||||||||||||||||||||
| 366 | 0 | push @cssfile, $name; | |||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||
| 370 | 0 | foreach (sort @cssfile) { | |||||||||||||||||||||||||||||||
| 371 | 0 | my $name = $_; | |||||||||||||||||||||||||||||||
| 372 | 0 | unshift @{$self->page_info->{css}}, | |||||||||||||||||||||||||||||||
| 373 | { | ||||||||||||||||||||||||||||||||
| 374 | name => $name . ' CSS', | ||||||||||||||||||||||||||||||||
| 375 | internal => $cache_path->child($name), | ||||||||||||||||||||||||||||||||
| 376 | external => $name | ||||||||||||||||||||||||||||||||
| 377 | }; | ||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | # Check if we need to request any new assets from hostname, otherwise use cached copies | ||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | foreach my $curr_asset (grep { defined $_ && $_->{internal} } map { @{$self->page_info->{$_}} } (qw(js templates css locales))) { | ||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_ && $_->{'internal'}
MC/DC0%0/2
defined $_ && $_->{'internal'}
defined $_
$_->{'internal'}
Truth table0%0/3
A && B
A= defined $_B= $_->{'internal'}
| |||||||||||||||||||||||||||||||||
| 382 | 0 | $self->retrieve_and_cache($curr_asset, $from); | |||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub retrieve_and_cache { | ||||||||||||||||||||||||||||||
|
Subroutine
retrieve_and_cache: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 387 | 0 | my ($self, $asset, $sub_of) = @_; | |||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | return unless ($asset->{internal} && $asset->{external}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$asset->{"internal"} and $asset->{"external"}
MC/DC0%0/2
$asset->{"internal"} and $asset->{"external"}
$asset->{"internal"}
$asset->{"external"}
Truth table0%0/3
A and B
A= $asset->{"internal"}B= $asset->{"external"}
| |||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | 0 | my $to_file = $asset->{internal}; | |||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | my $path_start = (substr($asset->{external}, 0, 1) eq '/') ? '' : '/'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 393 | 0 | my $url = 'https://' . $self->hostname . $path_start . $asset->{external}; | |||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | my $prefix = ($sub_of) ? '[via ' . $sub_of->{name} . '] ' : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 395 | 0 | $prefix .= '[' . $asset->{name} . '] '; | |||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($to_file->exists && (time - $to_file->stat->ctime) < $self->app->cachesec) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$to_file->exists and time - $to_file->stat->ctime < $self->app->cachesec
MC/DC0%0/2
$to_file->exists and time - $to_file->stat->ctime < $self->app->cachesec
$to_file->exists
time - $to_file->stat->ctime < $self->app->cachesec
Truth table0%0/3
A and B
A= $to_file->existsB= time - $to_file->stat->ctime < $self->app->cachesec
| |||||||||||||||||||||||||||||||||
| 397 | 0 | $self->app->emit_debug($prefix . $to_file->basename . " recently cached -- no request made."); | |||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||
| 399 | else { | ||||||||||||||||||||||||||||||||
| 400 | 0 | $self->app->emit_debug($prefix . 'requesting from: ' . $url . '...'); | |||||||||||||||||||||||||||||||
| 401 | 0 | $to_file->remove; | |||||||||||||||||||||||||||||||
| 402 | 0 | $to_file->touchpath; | |||||||||||||||||||||||||||||||
| 403 | 0 | my ($expected_length, $bytes_received, $progress); | |||||||||||||||||||||||||||||||
| 404 | 0 | my $next_update = 0; | |||||||||||||||||||||||||||||||
| 405 | my $res = $self->app->http->request( | ||||||||||||||||||||||||||||||||
| 406 | HTTP::Request->new(GET => $url), | ||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 408 | 0 | my ($chunk, $res) = @_; | |||||||||||||||||||||||||||||||
| 409 | 0 | $bytes_received += length($chunk); | |||||||||||||||||||||||||||||||
| 410 | 0 | $to_file->append($chunk); | |||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | $expected_length //= $res->content_length || 0; | ||||||||||||||||||||||||||||||
|
Condition0%0/4
$expected_length //= $res->content_length || 0
$res->content_length || 0
MC/DC0%0/1
$expected_length //= $res->content_length || 0
$expected_length
Truth table0%0/2
A
A= $expected_length
| |||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | return unless $self->app->verbose; # Progress bar is just for verbose mode; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if ($expected_length && !defined($progress)) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$expected_length and not defined $progress
MC/DC0%0/2
$expected_length and not defined $progress
$expected_length
not defined $progress
Truth table0%0/3
A and not(B)
A= $expected_lengthB= not defined $progress
| |||||||||||||||||||||||||||||||||
| 414 | 0 | $progress = Term::ProgressBar->new({ | |||||||||||||||||||||||||||||||
| 415 | name => $prefix, | ||||||||||||||||||||||||||||||||
| 416 | count => $expected_length, | ||||||||||||||||||||||||||||||||
| 417 | remove => 1, | ||||||||||||||||||||||||||||||||
| 418 | ETA => 'linear', | ||||||||||||||||||||||||||||||||
| 419 | fh => \*STDOUT, | ||||||||||||||||||||||||||||||||
| 420 | }); | ||||||||||||||||||||||||||||||||
| 421 | 0 | $progress->minor(0); | |||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||
| 423 | ▶ | elsif ($progress && $bytes_received > $next_update) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$progress and $bytes_received > $next_update
MC/DC0%0/2
$progress and $bytes_received > $next_update
$progress
$bytes_received > $next_update
Truth table0%0/3
A and B
A= $progressB= $bytes_received > $next_update
| |||||||||||||||||||||||||||||||||
| 424 | 0 | $next_update = $progress->update($bytes_received); | |||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||
| 426 | 0 | }); | |||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if (!$res->is_success) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 428 | 0 | $self->app->emit_and_exit(1, qq~$prefix request failed with response: ~ . $res->status_line . "\n"); | |||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||
| 430 | ▶ | elsif ($expected_length && $bytes_received < $expected_length) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$expected_length and $bytes_received < $expected_length
MC/DC0%0/2
$expected_length and $bytes_received < $expected_length
$expected_length
$bytes_received < $expected_length
Truth table0%0/3
A and B
A= $expected_lengthB= $bytes_received < $expected_length
| |||||||||||||||||||||||||||||||||
| 431 | 0 | $to_file->remove; | |||||||||||||||||||||||||||||||
| 432 | 0 | $self->app->emit_and_exit(1, qq~$prefix only $bytes_received of $expected_length bytes received~); | |||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||
| 434 | else { | ||||||||||||||||||||||||||||||||
| 435 | 0 | ▶ | $progress->update($expected_length) if ($progress && $expected_length); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$progress and $expected_length
MC/DC0%0/2
$progress and $expected_length
$progress
$expected_length
Truth table0%0/3
A and B
A= $progressB= $expected_length
| |||||||||||||||||||||||||||||||||
| 436 | 0 | $self->app->emit_debug($prefix . 'written to cache: ' . $to_file); | |||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||
| 439 | # We need to load the assets on the SERPs for reuse. | ||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | if ($asset->{load_sub_assets}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 441 | 0 | $self->app->emit_debug($prefix . 'parsing for additional assets'); | |||||||||||||||||||||||||||||||
| 442 | 0 | $self->get_sub_assets($asset); | |||||||||||||||||||||||||||||||
| 443 | 0 | $self->app->emit_debug($prefix . 'assets loaded'); | |||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||
| 446 | 0 | return; | |||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||
| 449 | 1 | 1; | |||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||
| 451 | __END__ | ||||||||||||||||||||||||||||||||