Wiki-Toolkit-Plugin-Ping-0.03/0002755000175000017500000000000011151076342014233 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/Changes0000644000175000017500000000063011151076263015525 0ustar domdom0.03 24 February 2009 Add Changes file to MANIFEST 0.02 31 January 2009 Skip database test when SQLite is not available (fixes cpantesters 2957644, 3047914, 3122378) Support configurable user-agent (#18) Sign distribution Cleanup test database in clean target 0.01 5 December 2006 Initial public release (missing this changelog file, oops) Wiki-Toolkit-Plugin-Ping-0.03/README0000644000175000017500000000116711141126766015123 0ustar domdomWiki::Toolkit::Plugin::Ping =========================== INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: LWP A database (one of MySQL, PostgreSQL or DBD::SQLite) is needed. USE One or more URLs to ping with a written node should be supplied at run-time COPYRIGHT AND LICENCE Copyright (C) 2006-2009 the Wiki::Toolkit team (http://www.wiki-toolkit.org/) All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Wiki-Toolkit-Plugin-Ping-0.03/SIGNATURE0000644000175000017500000000225011151076342015514 0ustar domdomThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.55. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 752bf00954e04560d2f8b192ef364de9c9c29b08 Changes SHA1 f4325f3662687896f8706afb5d13750b53ee1658 MANIFEST SHA1 cd69ba5b98f6272641b9b19de75463c81e935247 META.yml SHA1 390e48543b59b5af136cdc3b804bdb97c08f2cb6 Makefile.PL SHA1 3d23e470acadcd8b7dcfdd8f963fa136f0b8259e README SHA1 dfec05823a662cc26f9c4fd777d6fb63cdb450a6 lib/Wiki/Toolkit/Plugin/Ping.pm SHA1 905ef7a6f27f1ef757cd8a276f554f6babf9fdbe t/01_init.t SHA1 fe5108b030887ad3e0506916963353735da93840 t/02_call.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iD8DBQFJpHzfYzuFKFF44qURAsvfAJ9Atqnq8UOEmfA4KoXRttcCZ4tDOwCg95Yz 18hAsPvwQsO9sOWpI6Gvi/Q= =S5o1 -----END PGP SIGNATURE----- Wiki-Toolkit-Plugin-Ping-0.03/META.yml0000644000175000017500000000101211151076337015500 0ustar domdom--- #YAML:1.0 name: Wiki-Toolkit-Plugin-Ping version: 0.03 abstract: "ping" various services when nodes are written license: ~ author: - Nick Burch (openguides (at) gagravarr [dot] org) generated_by: ExtUtils::MakeMaker version 6.42 distribution_type: module requires: LWP: 0 Wiki::Toolkit: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Wiki-Toolkit-Plugin-Ping-0.03/MANIFEST0000644000175000017500000000037611151076337015374 0ustar domdomt/01_init.t t/02_call.t lib/Wiki/Toolkit/Plugin/Ping.pm Makefile.PL README MANIFEST Changes META.yml Module meta-data (added by MakeMaker) SIGNATURE Public-key signature (added by MakeMaker) Wiki-Toolkit-Plugin-Ping-0.03/t/0002755000175000017500000000000011151076337014502 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/t/01_init.t0000644000175000017500000000203011076405027016121 0ustar domdomuse strict; use Wiki::Toolkit; use Wiki::Toolkit::Plugin::Ping; use Test::More tests => 4; # Basic create my $plugin = Wiki::Toolkit::Plugin::Ping->new; ok( !undef $plugin, "Plugin was created OK with no URLs" ); # Several URls create my $plugin2 = Wiki::Toolkit::Plugin::Ping->new( node_to_url => 'http://localhost/\$node', services => { test => 'http://hello/?$url', test2 => 'http://hello/?$url', } ); ok( !undef $plugin2, "Plugin was created OK with no URLs" ); # One is missing the $url my $plugin3 = undef; eval { $plugin3 = Wiki::Toolkit::Plugin::Ping->new( node_to_url => 'http://localhost/\$node', services => { test => 'http://something/' } ); }; ok( ! $plugin3, "Can't create with a url missing \$url" ); # Don't give the URL builder my $plugin4 = undef; eval { $plugin4 = Wiki::Toolkit::Plugin::Ping->new( services => { test => 'http://something/$url' } ); }; ok( ! $plugin4, "Can't create with a node_to_url missing" ); Wiki-Toolkit-Plugin-Ping-0.03/t/02_call.t0000644000175000017500000000404411141056243016074 0ustar domdomuse strict; use Wiki::Toolkit; use Wiki::Toolkit::TestConfig; use Wiki::Toolkit::Plugin::Ping; use IO::Socket; use Test::More; eval { require DBD::SQLite; }; if ($@) { plan skip_all => 'SQLite not availalbe'; } else { plan tests => 5; } # Create a test wiki require Wiki::Toolkit::Setup::SQLite; my %config = %{$Wiki::Toolkit::TestConfig::config{"SQLite"}}; Wiki::Toolkit::Setup::SQLite::setup($config{dbname}); require Wiki::Toolkit::Store::SQLite; my $store = Wiki::Toolkit::Store::SQLite->new(%config); my $wiki = Wiki::Toolkit->new( store=>$store ); my $port = 112233; # Listen on a special port, so we can check a ping happened my $sock = new IO::Socket::INET ( LocalPort => $port, Proto => 'tcp', Listen => 1, ); unless($sock) { die("Can't listen on port $port for test"); } # Create, to call localhost my $plugin = Wiki::Toolkit::Plugin::Ping->new( node_to_url => "http://wiki.org/\$node", services => { test => "http://localhost:$port/url=\$url" }, agent => "Wiki::Toolkit::Plugin::Ping test suite", ); ok( $plugin, "Plugin was created OK with the local URL" ); # Register it $wiki->register_plugin(plugin=>$plugin); # Call post_write on it $plugin->post_write( node => "TestNode", id => 12, version => 1, content => "Stuff", metadata => {} ); # Check they actually sent us something my $rsock = $sock->accept(); my @req; my $going = 1; while($going && (my $line = <$rsock>)) { $line =~ s/\r?\n$//; unless($line) { $going = 0; } push @req,$line; warn "**$line**\n"; } # Check they requested the right thing my $allreq = join "\n", @req; like( $req[0], qr/^GET \/url=http:\/\/wiki.org\/TestNode/, "Did right get" ); like( $allreq, qr/^Host: localhost:$port/m, "Correct http/1.1 host" ); like( $allreq, qr/^User-Agent: Wiki::Toolkit::Plugin::Ping test suite/m, "Correct user-agent" ); # Send them an OK print $rsock "HTTP/1.0 200 OK\r\n\r\n"; # Close close($rsock); close($sock); # All happy ok( "Happy" ); Wiki-Toolkit-Plugin-Ping-0.03/Makefile.PL0000644000175000017500000000133111141126703016175 0ustar domdomuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( (MM->can('signature_target') ? (SIGN => 1) : ()), 'NAME' => 'Wiki::Toolkit::Plugin::Ping', 'VERSION_FROM' => 'lib/Wiki/Toolkit/Plugin/Ping.pm', # finds $VERSION 'PREREQ_PM' => {LWP => 0, Wiki::Toolkit => 0, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/Wiki/Toolkit/Plugin/Ping.pm', # retrieve abstract from module AUTHOR => 'Nick Burch (openguides (at) gagravarr [dot] org)') : ()), clean => { FILES => 't/sqlite-test.db' }, ); Wiki-Toolkit-Plugin-Ping-0.03/lib/0002755000175000017500000000000011151076337015005 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/lib/Wiki/0002755000175000017500000000000011151076337015710 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/lib/Wiki/Toolkit/0002755000175000017500000000000011151076337017335 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/lib/Wiki/Toolkit/Plugin/0002755000175000017500000000000011151076337020573 5ustar domdomWiki-Toolkit-Plugin-Ping-0.03/lib/Wiki/Toolkit/Plugin/Ping.pm0000644000175000017500000001066311151076327022031 0ustar domdompackage Wiki::Toolkit::Plugin::Ping; use strict; use warnings; use vars qw( @ISA $VERSION ); use Wiki::Toolkit::Plugin; use LWP; use LWP::UserAgent; @ISA = qw( Wiki::Toolkit::Plugin ); $VERSION = '0.03'; # Set things up sub new { my $class = shift; my %args = @_; my $self = {}; bless $self, $class; # Get list of services unless($args{services}) { $self->{services} = {}; return $self; } my %services = %{$args{services}}; # Get node -> URL mapping unless($args{node_to_url}) { die("Must supply 'node_to_url;"); } unless($args{node_to_url} =~ /\$node/) { die("node_to_url '$args{node_to_url}' must contain \$node"); } $self->{node_to_url} = $args{node_to_url}; $self->{agent} = $args{agent} || "Wiki::Toolkit::Plugin::Ping $VERSION"; # Check the services foreach my $service (keys %services) { my $url = $services{$service}; # Make valid unless($url =~ /^http:\/\//) { $url = "http://".$url; $services{$service} = $url; } unless($url =~ /\$url/) { die("For $service, URL '$url' didn't contain \$url anywhere\n"); } } # Save $self->{services} = \%services; # Done setup return $self; } # Return our list of services, in case anyone's interested sub services { my $self = shift; return %{$self->{services}}; } # Define our post_write plugin, which does the ping # Happens in another thread, to stop it slowing things down sub post_write { my $self = shift; unless(keys %{$self->{services}}) { return; } my %args = @_; my ($node,$node_id,$version,$content,$metadata) = @args{ qw( node node_id version content metadata ) }; # Spawn a new thread my $pid = fork(); if($pid) { # We're the main thread, return now return; } else { # We're the child, do the work # Apply the formatter escaping on the node name, if there's one if($self->formatter) { # Eval, in case the formatter doesn't support node name escaping eval { $node = $self->formatter->node_name_to_node_param($node); }; } # What's the URL of the node? my $node_url = $self->{node_to_url}; $node_url =~ s/\$node/$node/; # Get a LWP instance my $ua = LWP::UserAgent->new; $ua->agent($self->{agent}); # Ping each service foreach my $service (keys %{$self->{services}}) { # Build the ping URL my $ping_url = $self->{services}->{$service}; $ping_url =~ s/\$url/$node_url/; # Ping my $req = HTTP::Request->new(GET => $ping_url); my $res = $ua->request($req); unless($res->is_success) { warn("Error pinging $service: $res->status_line"); } } # All done, close the thread exit; } } # Returns a list of well known services sub well_known { return ( pingerati => 'http://pingerati.net/ping/$url', geourl => 'http://geourl.org/ping/?p=$url', ); } 1; __END__ =head1 NAME Wiki::Toolkit::Plugin::Ping - "ping" various services when nodes are written =head1 SYNOPSIS use Wiki::Toolkit::Plugin::Ping; my $ping = Wiki::Toolkit::Plugin::Ping->new( node_to_url => 'http://mywiki/$node', services => { "geourl" => 'http://geourl.org/ping?p=$url' }, agent => "My Wiki ping agent", ); $wiki->register_pugin( plugin => $ping ); =head1 DESCRIPTION A plug-in for Wiki::Toolkit sites, which will "ping" various external services when a node is written. A list of the services to ping, and where in their URLs to add the URL of the node, are supplied when the plugin is created. You need to tell it how to turn a node into a URL (node_to_url), and what services to ping (services). You can optionally pass a custom user-agent string =head1 AUTHOR The Wiki::Toolkit team (http://www.wiki-toolkit.org/) =head1 COPYRIGHT Copyright (C) 2003-2004 I. P. Williams (ivorw_openguides [at] xemaps {dot} com). Copyright (C) 2006-2009 the Wiki::Toolkit team (http://www.wiki-toolkit.org/) All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L =cut