File: update

package info (click to toggle)
libfile-listing-perl 6.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: perl: 295; sh: 8; makefile: 2
file content (33 lines) | stat: -rwxr-xr-x 765 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env perl

use strict;
use warnings;
use 5.020;
use Mojo::UserAgent;
use Mojo::URL;
use Path::Tiny qw( path );

my $root = Mojo::URL->new('http://localhost:8080');
my $ua = Mojo::UserAgent->new;

sub fetch
{
  my $path = shift || '/';
  my $url = $root->clone;
  $url->path($path);
  say "GET   $url";
  my $result = $ua->get($url)->result;
  $result->code == 200 or die "@{[ $result->code ]} @{[ $result->message ]}";
  return $result;
}

my $index_html = fetch();

foreach my $a ($index_html->dom->find('a')->each)
{
  my $name = $a->attr('href');
  my $doc = fetch("/$name/");
  my $output = path(__FILE__)->absolute->parent->parent->parent->child("corpus/apache-$name.html");
  say "WRITE file://localhost$output";
  $output->spew_utf8($doc->body);
}