Search::Sitemap::Pinger - Notify a specific search engines of sitemap updates


Search-Sitemap documentation Contained in the Search-Sitemap distribution.

Index


Code Index:

NAME

Top

Search::Sitemap::Pinger - Notify a specific search engines of sitemap updates

SYNOPSIS

Top

This package and it's subclasses are for internal use. The public interface to them is Search::Sitemap::Ping.

METHODS

Top

ALL_PINGERS

Called as a class method (usually as Search::Sitemap::Pinger-ALL_PINGERS>) returns a list of all the installed subclasses of Search::Sitemap::Pinger.

new

Create a new Search::Sitemap::Pinger object.

submit( [ $callback ], @urls );

Submit the urls to the search engine. If the first argument is a code reference, it will be used as a callback after each attempted URL submission. The callback code reference will be passed either the word 'success' or the word 'failure', followed by the url that was attempted, followed by either the HTML content that accompanied a success or the HTTP error message that accompanied a failure.

SEE ALSO

Top

Search::Sitemap

AUTHOR

Top

Jason Kohles, <email@jasonkohles.com>

COPYRIGHT AND LICENSE

Top


Search-Sitemap documentation Contained in the Search-Sitemap distribution.

package Search::Sitemap::Pinger;
use strict; use warnings;
our $VERSION = '2.13';
our $AUTHORITY = 'cpan:JASONK';
use Moose;
use LWP::UserAgent;
use MooseX::Types::Moose qw( ArrayRef Str HashRef );
use MooseX::Types::URI qw( Uri );
use URI;
use Module::Find qw( usesub );
use Class::Trigger qw(
    before_submit after_submit
    before_submit_url after_submit_url
    success failure
);
use namespace::clean -except => [qw( meta add_trigger call_trigger )];

sub ALL_PINGERS { grep { $_ ne __PACKAGE__ } usesub( __PACKAGE__ ) }

has 'user_agent'    => (
    is      => 'rw',
    isa     => 'LWP::UserAgent',
    lazy    => 1,
    default => sub {
        my $self = shift;
        LWP::UserAgent->new(
            timeout     => 10,
            env_proxy   => 1,
        );
    },  
);      

sub submit {
    my $self = shift;
    my $cb = ( ref $_[0] eq 'CODE' ) ? shift : undef;

    for my $url ( @_ ) {
        my $submit_url = $self->submit_url_for( "$url" );
        my $response = $self->user_agent->get( $submit_url );
        if ( $response->is_success ) {
            if ( $cb ) { $cb->( success => $url, $response->content ) }
            $self->call_trigger( success => $url, $response->content );
        } else {
            if ( $cb ) { $cb->( failure => $url, $response->status_line ) }
            $self->call_trigger( failure => $url, $response->status_line );
        }
    }
}

__PACKAGE__->meta->make_immutable;
1;
__END__