CPAN-Mini-Live

 view release on metacpan or  search on metacpan

lib/CPAN/Mini/Live.pm  view on Meta::CPAN

package CPAN::Mini::Live;
use strict;
use warnings;
use AnyEvent::FriendFeed::Realtime;
use base qw( CPAN::Mini );
our $VERSION = '0.33';

sub update_mirror {
    my $self = shift;
    $self = $self->new(@_) unless ref $self;

    # first we have to catch up if we've missed anything
    $self->trace("updating mirror...\n");
    $self->SUPER::update_mirror();

    # and now we try being live
    $self->trace("and live...\n");
    my $done   = AnyEvent->condvar;
    my $client = AnyEvent::FriendFeed::Realtime->new(
        request  => '/feed/minicpan',
        on_entry => sub {
            my $entry = shift;
            my $body  = $entry->{body};
            my ($action) = $body =~ /^(.+?) /;
            my ($uri)    = $body =~ /href="(.+?)"/;
            my $path     = $uri;
            my $remote   = $self->{remote};
            $path =~ s/^$remote//;
            my $local_file
                = File::Spec->catfile( $self->{local}, split m{/}, $path );
            $self->trace("live [$action] [$path]\n");

            if ( $action eq 'mirror_file' ) {
                $self->mirror_file($path);
            } elsif ( $action eq 'clean_file' ) {
                $self->clean_file($local_file);
            } else {
                warn "ERROR: unknown action $action";
                $done->send;
            }
        },
        on_error => sub {
            warn "ERROR: $_[0]";
            $done->send;
        },
    );
    $done->recv;
}

1;

__END__

=head1 NAME

CPAN::Mini::Live - Keep CPAN Mini up to date

=head1 SYNOPSIS

  # have a ~/.minicpanrc:
  # (change local to where you want the mirror)
  remote: http://cpan.cpantesters.org/
  exact_mirror: 1
  force: 0
  trace: 0
  class: CPAN::Mini::Live
  local: /home/acme/Public/minicpanlive/



( run in 1.746 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )