X-Git-Url: http://erislabs.net/gitweb/?p=libwww-opensearch-perl.git;a=blobdiff_plain;f=lib%2FWWW%2FOpenSearch%2FDescription.pm;h=8af4bd8727ec52a56ee97b0d493dbde7244b1e32;hp=0075e355ca2fbf6c99da6a534aa01037f717a11f;hb=3e29d833e4fbe59c83e7ae52a7413b193c1083bd;hpb=5127c597102ab37e43b89cc43b4d8ea1b34509cd diff --git a/lib/WWW/OpenSearch/Description.pm b/lib/WWW/OpenSearch/Description.pm index 0075e35..8af4bd8 100644 --- a/lib/WWW/OpenSearch/Description.pm +++ b/lib/WWW/OpenSearch/Description.pm @@ -89,6 +89,8 @@ whose type is equal to $type. =head2 AdultContent( ) +=head2 Attribution( ) + =head2 Contact( ) =head2 Description( ) @@ -97,10 +99,16 @@ whose type is equal to $type. =head2 Format( ) +=head2 InputEncoding( ) + =head2 Image( ) +=head2 Language( ) + =head2 LongName( ) +=head2 OutputEncoding( ) + =head2 Query( ) =head2 SampleSearch( ) @@ -132,7 +140,7 @@ it under the same terms as Perl itself. =cut -for( @columns ) { +for ( @columns ) { no strict 'refs'; my $col = lc; *$_ = \&$col; @@ -141,11 +149,11 @@ for( @columns ) { sub new { my $class = shift; my $xml = shift; - - my $self = $class->SUPER::new; - - eval{ $self->load( $xml ); } if $xml; - if( $@ ) { + + my $self = $class->SUPER::new; + + eval { $self->load( $xml ); } if $xml; + if ( $@ ) { croak "Error while parsing Description XML: $@"; } @@ -155,17 +163,18 @@ sub new { sub load { my $self = shift; my $xml = shift; - + my $parser = XML::LibXML->new; my $doc = $parser->parse_string( $xml ); my $element = $doc->documentElement; my $nodename = $element->nodeName; - croak "Node should be OpenSearchDescription: $nodename" if $nodename ne 'OpenSearchDescription'; + croak "Node should be OpenSearchDescription: $nodename" + if $nodename ne 'OpenSearchDescription'; my $ns = $element->getNamespace->value; my $version; - if( $ns eq 'http://a9.com/-/spec/opensearchdescription/1.0/' ) { + if ( $ns eq 'http://a9.com/-/spec/opensearchdescription/1.0/' ) { $self->ns( 'http://a9.com/-/spec/opensearchrss/1.0/' ); $version = '1.0'; } @@ -176,10 +185,18 @@ sub load { $self->version( $version ); for my $column ( @columns ) { - my $node = $doc->documentElement->getChildrenByTagName( $column ) or next; - if( $column eq 'Url' ) { - if( $version eq '1.0' ) { - $self->Url( [ WWW::OpenSearch::Url->new( template => $node->string_value, type => 'application/rss+xml', ns => $self->ns ) ] ); + my $node = $doc->documentElement->getChildrenByTagName( $column ) + or next; + if ( $column eq 'Url' ) { + if ( $version eq '1.0' ) { + $self->Url( + [ WWW::OpenSearch::Url->new( + template => $node->string_value, + type => 'application/rss+xml', + ns => $self->ns + ) + ] + ); next; } @@ -187,43 +204,57 @@ sub load { for my $urlnode ( $node->get_nodelist ) { my $type = $urlnode->getAttributeNode( 'type' )->value; my $url = $urlnode->getAttributeNode( 'template' )->value; - $url =~ s/\?}/}/g; # optional + $url =~ s/\?}/}/g; # optional my $method = $urlnode->getAttributeNode( 'method' ); $method = $method->value if $method; my %params; - for( $urlnode->getChildrenByTagName( 'Param' ) ) { + for ( $urlnode->getChildrenByTagName( 'Param' ) ) { my $param = $_->getAttributeNode( 'name' )->value; my $value = $_->getAttributeNode( 'value' )->value; - $value =~ s/\?}/}/g; # optional + $value =~ s/\?}/}/g; # optional $params{ $param } = $value; } - push @url, WWW::OpenSearch::Url->new( template => $url, type => $type, method => $method, params => \%params, ns => $self->ns ); + push @url, + WWW::OpenSearch::Url->new( + template => $url, + type => $type, + method => $method, + params => \%params, + ns => $self->ns + ); } $self->Url( \@url ); } - elsif( $version eq '1.1' and $column eq 'Query' ) { + elsif ( $version eq '1.1' and $column eq 'Query' ) { my $queries = $self->query || []; for my $node ( $node->get_nodelist ) { - my $query = WWW::OpenSearch::Query->new( { - map { $_ => $node->getAttributeNode( $_ )->value } qw( role searchTerms ) - } ); + my $query = WWW::OpenSearch::Query->new( + { map { $_ => $node->getAttributeNode( $_ )->value } + qw( role searchTerms ) + } + ); push @$queries, $query; } $self->query( $queries ); } - elsif( $version eq '1.1' and $column eq 'Image' ) { + elsif ( $version eq '1.1' and $column eq 'Image' ) { my $images = $self->image || []; for my $node ( $node->get_nodelist ) { - my $image = WWW::OpenSearch::Image->new( { - ( map { my $attr = $node->getAttributeNode( $_ ); $attr ? ($_ => $attr->value) : () } qw( height width type ) ), - url => $node->string_value - } ); + my $image = WWW::OpenSearch::Image->new( + { ( map { + my $attr = $node->getAttributeNode( $_ ); + $attr ? ( $_ => $attr->value ) : () + } qw( height width type ) + ), + url => $node->string_value + } + ); push @$images, $image; } @@ -238,8 +269,9 @@ sub load { sub get_best_url { my $self = shift; - - return $self->get_url_by_type( 'application/atom+xml' ) + + return + $self->get_url_by_type( 'application/atom+xml' ) || $self->get_url_by_type( 'application/rss+xml' ) || $self->get_url_by_type( 'text/xml' ) || $self->url->[ 0 ]; @@ -248,11 +280,11 @@ sub get_best_url { sub get_url_by_type { my $self = shift; my $type = shift; - - for( $self->urls ) { + + for ( $self->urls ) { return $_ if $_->type eq $type; - }; - + } + return; }