Net::Douban::Roles - basic Moose role for Net::Douban


Net-Douban documentation Contained in the Net-Douban distribution.

Index


Code Index:

NAME

Top

Net::Douban::Roles - basic Moose role for Net::Douban

VERSION

Top

version 1.07

SYNOPSIS

Top

	with 'Net::Douban::Roles'

DESCRIPTION

Top

This PM file includes Net::Douban::Roles and Net::Douban::Types. Net::Douban::Roles provides most of the attributes for Net::Douban::*; Net::Douban::Types is the type constraint system for Net::Douban

ATTRIBUTES

Top

oauth

oauth object for Net::Douban

ua

user-agent object for Net::Douban, provided by default

apikey
private_key
start_index

url start-index argument, set to 0 by default

max_results

url max-results argument, set to 10 by default

SEE ALSO

Top

Net::Douban Net::Douban::Roles::More Moose http://douban.com/service/apidoc

AUTHOR

Top

woosley.xu<redicaps@gmail.com>

COPYRIGHT & LICENSE

Top


Net-Douban documentation Contained in the Net-Douban distribution.

package Net::Douban::Roles;

our $VERSION = '1.07';
use Carp qw/carp croak/;
use Moose::Role;
use Scalar::Util qw/blessed/;

has 'oauth' => (is => 'rw', predicate => 'has_oauth');

has 'ua' => (
    is         => 'rw',
    lazy_build => 1,
);

sub _build_ua {
    eval { require LWP::UserAgent };
    croak $@ if $@;
    my $ua = LWP::UserAgent->new(
        agent        => 'perl-net-douban-' . $VERSION,
        timeout      => 30,
        max_redirect => 5
    );
    $ua->env_proxy;
    $ua;
}

has 'apikey' => (
    is  => 'rw',
    isa => 'Str',
);

has 'private_key' => (
    is  => 'rw',
    isa => 'Str',
);

has 'start_index' => (
    is      => 'rw',
    isa     => 'PInt',
    default => 0,
);

has 'max_results' => (
    is      => 'rw',
    isa     => 'PInt',
    default => 10,
);

sub args {
    my $self = shift;
    my %ret;
    for my $arg (qw/ ua apikey start_index max_results oauth/) {
        if (defined $self->$arg) {
            $ret{$arg} = $self->$arg;
        }
    }
    return %ret;
}

no Moose::Role;

package Net::Douban::Types;
use Moose::Util::TypeConstraints;

## url
subtype
  'Url' => as 'Str',
  => where { $_ =~ m/^http:\/\/.*\w$/ },
  => message {"invalid url!"};

## positive int
subtype
  'PInt' => as 'Int',
  => where { $_ >= 0 },
  => message {"not a positive int"};
1;
__END__