1 |
package Frey::Mirror; |
2 |
use Moose; |
3 |
|
4 |
=head1 DESCRIPTION |
5 |
|
6 |
Mirror content from web and store it locally |
7 |
|
8 |
=head1 SYNOPSYS |
9 |
|
10 |
my $content = Frey::Mirror->new( uri => 'http://www.example.com' )->content; |
11 |
|
12 |
=cut |
13 |
|
14 |
use Frey::Types; |
15 |
use LWP::Simple; |
16 |
use File::Slurp; |
17 |
|
18 |
with 'Frey::Path'; |
19 |
|
20 |
has uri => ( |
21 |
is => 'rw', |
22 |
isa => 'Uri', coerce => 1, |
23 |
required => 1, |
24 |
default => 'http://blog.rot13.org/index.xml', |
25 |
); |
26 |
|
27 |
has content => ( |
28 |
is => 'ro', |
29 |
required => 1, |
30 |
lazy => 1, |
31 |
default => sub { |
32 |
my ($self) = @_; |
33 |
my $path = 'var/mirror/' . $self->uri->host . '/' . $self->uri->path; |
34 |
if ( ! -e $path ) { |
35 |
$self->mkbasepath( $path ); |
36 |
mirror( $self->uri, $path ); |
37 |
warn "mirror ", $self->uri, " -> $path ", -s $path, " bytes"; |
38 |
} |
39 |
read_file( $path ); |
40 |
}, |
41 |
); |
42 |
|
43 |
1; |