Changeset 109

Show
Ignore:
Timestamp:
06/25/01 19:04:47
Author:
miyagawa
Message:

more document

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WWW-Cache-Google/trunk/lib/WWW/Cache/Google.pm

    r77 r109  
    33use strict; 
    44use vars qw($VERSION @ISA @EXPORT_OK); 
    5 $VERSION = '0.01'; 
     5$VERSION = '0.02'; 
    66 
    77require Exporter; 
     
    1515sub url2google { 
    1616    my $url = shift; 
    17     return WWW::Cache::Google->new($url)->as_string; 
     17    return __PACKAGE__->new($url)->as_string; 
    1818} 
    1919 
    2020sub get_google_cache { 
    2121    my $url = shift; 
    22     return WWW::Cache::Google->new($url)->fetch; 
     22    return __PACKAGE__->new($url)->fetch; 
    2323} 
    2424 
    25 # lexical scope for class variables 
    26 
    27     my $base = 'http://www.google.com/search?q=cache:%s'; 
    28     sub google_cache_base { 
    29         my $class = shift; 
    30         $base = shift if @_; 
    31         $base; 
    32     } 
     25sub cache_base { 
     26    return 'http://www.google.com/search?q=cache:%s'; 
    3327} 
     28 
     29 
     30# ro-accessor 
     31sub orig   { $_[0]->[0] } 
     32sub cache  { $_[0]->[1] } 
    3433 
    3534sub new { 
     
    4948sub init { 
    5049    my $self = shift; 
    51     my $uri = sprintf $self->google_cache_base, $self->_cache_param; 
     50    my $uri = sprintf $self->cache_base, $self->_cache_param; 
    5251    $self->[1] = URI->new($uri); 
    5352} 
     
    5756    return $self->orig->host . uri_escape($self->orig->path_query, q(\W)); 
    5857} 
    59  
    60 # ro-accessor 
    61 sub orig   { $_[0]->[0] } 
    62 sub cache  { $_[0]->[1] } 
    6358 
    6459sub fetch { 
     
    8984 
    9085  # OO decorator way 
    91   $cache = WWW::Cache::Google->new(URI->new('http://www.yahoo.com/')); 
     86  $cache = WWW::Cache::Google->new('http://www.yahoo.com/'); 
    9287 
    93   print $cache->as_string; # cache URL 
    94   print $cache; # overloaded 
    95  
    96   $html = $cache->fetch; # fetches via LWP::Simple 
     88  $url  = $cache->as_string;    # cache URL 
     89  $html = $cache->fetch;        # fetches via LWP::Simple 
    9790 
    9891  # functional way 
     
    10396=head1 DESCRIPTION 
    10497 
     98404 Not Found. But wait ... there's a google cache! 
     99 
    105100WWW::Cache::Google provides an easy way conversion from an URL to 
    106101Google cache URL. 
     102 
     103=head1 METHODS 
     104 
     105=over 4 
     106 
     107=item $cache = WWW::Cache::Google->new($url); 
     108 
     109constructs WWW::Cache::Google instance. 
     110 
     111=item $orig_uri = $cache->orig; 
     112 
     113returns original URL as URI instance. 
     114 
     115=item $cache_uri = $cache->cache; 
     116 
     117returns Google cache URL as URI instance. 
     118 
     119=item $html = $cache->fetch; 
     120 
     121gets HTML contents of Google cache. Requires L<LWP::Simple>. 
     122 
     123=item $url_str = $cache->as_string; 
     124 
     125returns Google cache's URL as string. Every method defined in URI 
     126class is autoloaded through $cache->cache. See L<URI> for details. 
     127 
     128=back 
     129 
     130=head1 FUNCTIONS 
     131 
     132Following functions are provided for non-OO programmers, or one-liners. 
     133 
     134=over 4 
     135 
     136=item $cache_url = url2google($url); 
     137 
     138converts URL to Google cache URL. Same as 
     139 
     140  $cache_url = WWW::Cache::Google->new($url)->as_string; 
     141 
     142 
     143=item $cache_html = get_google_cache($url); 
     144 
     145returns HTML contents of Google cache. Same as: 
     146 
     147  $cache_html = WWW::Cache::Google->new($url)->fetch; 
     148 
     149=back 
     150 
     151These functions are not exported by default. 
     152 
    107153 
    108154=head1 AUTHOR