Changeset 1711

Show
Ignore:
Timestamp:
01/10/06 03:33:08
Author:
miyagawa
Message:

0.05; OpenSearch? 1.1 support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WWW-OpenSearch/trunk/Changes

    r1614 r1711  
    11Revision history for Perl extension WWW::OpenSearch 
    22 
     30.05  Mon Jan  9 18:30:18 UTC 2006 
     4        - Added partial support of OpenSearch 1.1. There's no API change and 
     5          old elements just work as before, with 1.1 OpenSearch document as 
     6          well. See http://opensearch.a9.com/docs/upgrading10.jsp 
     7          (Thanks to Masaaki Hirose) 
     8           
    390.04  Sat Jul 29 18:34:31 PDT 2005 
    410        - Drop off XML::Simple for efficiency. 
  • WWW-OpenSearch/trunk/MANIFEST

    r1614 r1711  
    77t/01_live.t 
    88t/02_paginate.t 
     9META.yml                                 Module meta-data (added by MakeMaker) 
  • WWW-OpenSearch/trunk/lib/WWW/OpenSearch.pm

    r1614 r1711  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = '0.04'; 
     5$VERSION = '0.05'; 
    66 
    77use Carp; 
     
    1414my @Cols = qw( 
    1515Url Format ShortName LongName Description Tags Image SampleSearch 
    16 Developer Contact SyndicationRight AdultContent 
     16Developer Contact SyndicationRight AdultContent Query 
    1717); 
    1818for my $col (@Cols) { 
     
    4646        unless $response->is_success; 
    4747    eval { 
    48         my $data = parse_description($response->content); 
     48        my $data = $self->parse_description($response->content); 
    4949        for my $attr (keys %$data) { 
    5050            $self->{$attr} = $data->{$attr}; 
     
    5656} 
    5757 
     58sub version { 
     59    my $self = shift; 
     60    $self->{version} = shift if @_; 
     61    $self->{version}; 
     62} 
     63 
    5864sub parse_description { 
    59     my $xml = shift; 
     65    my $self = shift; 
     66    my($xml) = @_; 
    6067    my $parser = XML::LibXML->new; 
    6168    my $doc = $parser->parse_string($xml); 
    62     my $nodename = $doc->documentElement->nodeName; 
     69    my $element  = $doc->documentElement; 
     70    my $nodename = $element->nodeName; 
    6371    croak "Node should be OpenSearchDescription: $nodename" 
    6472        if $nodename ne "OpenSearchDescription"; 
     73 
     74    my $ns = $element->getNamespace->value; 
     75    if ($ns eq "http://a9.com/-/spec/opensearch/1.1/") { 
     76        $self->version("1.1"); 
     77    } else { 
     78        $self->version("1.0"); 
     79    } 
     80 
    6581    my %data; 
    6682    for my $col (@Cols) { 
    67         my $node = $doc->documentElement->getChildrenByTagName($col); 
    68         $data{$col} = $node->string_value if $node; 
     83        my $node = $doc->documentElement->getChildrenByTagName($col) or next; 
     84        if ($self->version eq '1.1' && $col eq 'Url') { 
     85            my $urlnode = ($node->get_nodelist)[0]; 
     86            my $type = $urlnode->getAttributeNode('type')->value; 
     87            if ($type ne 'application/rss+xml') { 
     88                croak "Url/\@type $type is not supported by this module. It should be application/rss+xml"; 
     89            } 
     90            $data{$col} = $urlnode->getAttributeNode('template')->value; 
     91            $data{$col} =~ s/\?}/}/g; # optional 
     92        } elsif ($self->version eq '1.1' && $col eq 'Query') { 
     93            my $thisnode = ($node->get_nodelist)[0]; 
     94            next if $thisnode->getAttributeNode('role')->value eq 'example'; 
     95            $data{SampleSearch} = $thisnode->getAttributeNode('searchTerms')->value; 
     96        } else { 
     97            $data{$col} = $node->string_value; 
     98        } 
    6999    } 
     100 
    70101    \%data; 
    71102}