| Net-Douban documentation | Contained in the Net-Douban distribution. |
Net::Douban::Entry
version 1.07
use Net::Douban::Atom;
my $feed = Net::Douban::Atom->new(\$xml);
my @entries = $feed->entries;
$entry->get('title');
$entry->content;
$entry->attributes;
$entry->tags;
This is the parser of douban.com xml entry based on XML::Atom::Entry and Moose
Many functions not listed here are documented in XML::Atom::Entry
$entry->content();
返回content内容
$entry->attributes;
返回包含所有attribute的hash引用
$entry->tags;
返回包括所有tag的数组引用
$entry->rating;
返回一个rating的hash引用
woosley.xu<redicaps@gmail.com>
Copyright (C) 2010 by Woosley.Xu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
| Net-Douban documentation | Contained in the Net-Douban distribution. |
package Net::Douban::Entry; BEGIN { $Net::Douban::Entry::VERSION = '1.07'; } use Moose; use MooseX::StrictConstructor; use Net::Douban::DBSubject; use Carp qw/carp croak/; #use Smart::Comments; extends qw/XML::Atom::Entry/; has 'namespace' => ( is => 'ro', isa => 'HashRef', required => 1, ); sub new { my $class = shift; my %args = @_; my $ns = delete $args{namespace}; my $self = $class->SUPER::new(%args); return $class->meta->new_object(__INSTANCE__ => $self, namespace => $ns); } sub get { my $self = shift; my ($ns, $field); if (@_ == 1) { $field = shift; if ($field =~ /^(.*?):(.*)$/) { $ns = $self->namespace->{$1}; $field = $2; } else { $ns = $self->{ns}; } } else { ($ns, $field) = @_; $ns = $self->namespace->{$ns} unless $ns =~ m{^http://}; } $ns or croak "No Namespace found!"; $self->SUPER::get($ns, $field); } sub content { return $_[0]->SUPER::content->body; } sub attributes { my $self = shift; my $ns = $self->namespace->{db}; my %attr; foreach my $node ($self->elem->getChildrenByTagNameNS($ns, 'attribute')) { $attr{$node->getAttribute('name')} = $node->textContent; } \%attr; } sub tags { my $self = shift; my $ns = $self->namespace->{db}; my @tags; foreach my $node ($self->elem->getChildrenByTagNameNS($ns, 'tag')) { push @tags, $node->getAttribute('name'); } \@tags; } sub rating { my $self = shift; my %rating; my $rate = ($self->elem->getChildrenByTagNameNS($self->namespace->{gd}, 'rating')) [0]; foreach my $attr ($rate->attributes) { $rating{$attr->nodeName} = $attr->value; } \%rating; } sub subject { my $self = shift; my $subject = ( $self->elem->getChildrenByTagNameNS( $self->namespace->{db}, 'subject' ) )[0]; ### subject: $subject return unless ref $subject eq 'XML::LibXML::Element'; my $k = Net::Douban::DBSubject->new( Elem => $subject, namespace => $self->namespace, ); $k->{ns} = $self->namespace->{main}; return $k; } #sub DESTROY { } #our $AUTOLOAD; # #sub AUTOLOAD { # # # my $self = shift; # # my $class = ref $self ? ref $self : $self; # (my $name = $AUTOLOAD) =~ s/.*:://g; # return if $name eq 'DESTROY'; # my $sub = <<SUB; # sub $name { # my \$self = shift; # return \$self->get($name); # } #SUB # eval($sub); ## the same as *$name = $sub; # goto &$name; #} 1; __END__