24 |
required => 1, |
required => 1, |
25 |
); |
); |
26 |
|
|
27 |
|
has 'mirror' => ( |
28 |
|
is => 'rw', |
29 |
|
isa => 'Boolean', |
30 |
|
); |
31 |
|
|
32 |
#use String::TT qw/strip tt/; |
#use String::TT qw/strip tt/; |
33 |
|
|
34 |
use pQuery; |
use pQuery; |
35 |
use File::Slurp; |
use File::Slurp; |
36 |
use LWP::Simple; |
use LWP::Simple (); |
37 |
use File::Path; |
use File::Path; |
38 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
39 |
|
|
42 |
} |
} |
43 |
|
|
44 |
sub mirror_design { |
sub mirror_design { |
45 |
my ( $url, $path ) = @_; |
my ( $self, $c, $path ) = @_; |
46 |
return if -e $path; |
return if -e $path; |
47 |
|
|
48 |
|
return unless $self->mirror; |
49 |
|
|
50 |
|
my $url = $self->uri . '/' . $c->req->path . '?' . $c->req->uri->query; |
51 |
|
|
52 |
my $base_path = $path; |
my $base_path = $path; |
53 |
$base_path =~ s{/[^/]+$}{}; |
$base_path =~ s{/[^/]+$}{}; |
54 |
mkpath $base_path if ! -e $base_path; |
mkpath $base_path if ! -e $base_path; |
55 |
|
|
56 |
warn ">> mirror $url -> $path\n"; |
warn ">> mirror $url -> $path\n"; |
57 |
|
|
58 |
mirror( $url, $path ) or die "can't mirror $url: $!"; |
LWP::Simple::mirror( $url, $path ) or die "can't mirror $url: $!"; |
59 |
} |
} |
60 |
|
|
61 |
sub handler { |
sub handler { |
71 |
|
|
72 |
my $url = $self->uri; |
my $url = $self->uri; |
73 |
|
|
74 |
mirror_design( $url . $c->req->path, $path ); |
$self->mirror_design( $c, $path ); |
75 |
|
|
76 |
$body .= read_file( $path ); |
$body .= read_file( $path ); |
77 |
|
|
92 |
my $dom = pQuery( $body ); |
my $dom = pQuery( $body ); |
93 |
# warn dump( $dom->find("body") ); |
# warn dump( $dom->find("body") ); |
94 |
$dom->find(".navigation")->each( sub { |
$dom->find(".navigation")->each( sub { |
95 |
warn dump( $_->innerHTML ); |
my $html = $_->innerHTML; |
96 |
|
warn $html; |
97 |
|
# $_->innerHTML(qq{ |
98 |
|
# <div style="border: 3px dashed black;">$html</div> |
99 |
|
# }); |
100 |
} ); |
} ); |
101 |
|
|
102 |
|
# $body = $dom->toHtml; |
103 |
|
|
104 |
} |
} |
105 |
|
|
106 |
warn "<< ", $c->req->path, " ", -s $path, " ", $c->res->content_type, "\n"; |
warn "<< ", $c->req->path, |
107 |
|
" ", -s $path, |
108 |
|
" ", $c->res->content_type, |
109 |
|
" ", $c->req->params ? dump( $c->req->params ) : '', |
110 |
|
"\n"; |
111 |
|
|
112 |
=for later |
=for later |
113 |
|
|