Yaron Kahanovitch > WWW-Monitor-0.24 > WWW::Monitor



Annotate this POD

View/Report Bugs
Module Version: 0.24   Source  


WWW::Monitor - Monitor websites for updates and changes


Version 0.01


     use MIME::Lite;
     use WWW::Monitor;
     sub notify {
       my ($url,$text) =@_;
       foreach my $recipient ('user1@host','user2@host2') {
         my $mail_obj =
                           Subject=>"Web alert web page changed",
                           Data=>'For details visit '.$url."\n".$text
       return 1;
     my $mon = WWW::Monitor->new('MAIL_CALLBACK'=>\&notify);


     use WWW::Monitor;
     my $mon=WWW::Monitor->new('MAIL_CALLBACK'=>\&notify,'CACHE'=>$cache);
     my $task = $mon->watch("$url");
     $mon->run or die "Query ended with error";
     sun notify {
         my ($url,$task) =@_;
         print "$url has changed\n";
         while (my ($sub_url,$ref_http_response) = each %{$task->added_parts()}) {
           print "New part added: $sub_url \n";
         while (my ($sub_url,$ref_http_response) = each %{$task->missing_parts()}) {
           print "Part deleted: $sub_url \n";
        foreach my $sub_url ( $task->changed_parts()) {
           print "$sub_url has changed:\n";
           my ($old,$new) = $task->get_old_new_pair($sub_url);
           my $old_content = $old->content;
           my $new_content = $new->content;

Description ^

WWW::Monitor ia a Web monitoring mechanism built to detect and notify changes in web pages. The module is designed to compare existing, online versions and pre-cached matched version. A web page may include more than one file. A page may include some frames and visible referenced data, which all together form a sigle visible page. For now, WWW::Monitor compares only textual information. Images, and non-HTML data are not being compared. To store information, WWW::Monitor caches data with the "Cache" mechanism. By default, Cache::File is being used, but the user may choose to use any Cache object that implements the Cache module interface. WWW::Monitor is a subclass of WWW::Mechanize, so any of WWW::Mechanize or its super classes can be used.



new ( [ OPTIONS ] )

A constructor. OPTIONS are passed in a hash like fashion, using key and value pairs. Possible options are: URL - A target URL to monitor. CACHE_ROOT - A root directory under which all caching is being managed. Default = <home directory>/.www-monitor CACHE - cache object. The object must have get() and set() methods like the Cache interface, as well as set_validity and validity.

watch ( URL(S) )

Add URL to be watched. watch returns a reference to a WWW::Monitor::Task object. for example $obj->watch('http://www.cnn.com' )

notify_callback ( sub )

A code reference to be executed whenever a change is detected (commonly used for sending mail). The following parameters will be passed to the code reference: $url -> a string that holds the url for which a change was detected. $text -> A Message to be sent. $task -> WWW::Monitor::Task object reference. The given code reference should return true for success.


Watch all given web pages and report changes if detected. If a url is first visited (i.e. the url is not in the cache db) than the url will be cached and no report will be created.


Return a hash reference of errors updated to last execution (i.e. when the run method was last executed). The returned keys are the urls where the values are error descriptions.


return a string that contains all errors. In array context return a list of errors.


(Private Method) Activate notification callback


Return a list of strings out of watched targets.


Yaron Kahanovitch, <yaron-helpme at kahanovitch.com>


Please report any bugs or feature requests to bug-www-monitor at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Monitor. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command. perldoc WWW::Monitor



Copyright 2007 Yaron Kahanovitch, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: