File Coverage

blib/lib/WWW/Mixi/OO.pm
Criterion Covered Total %
statement 12 43 27.9
branch 0 20 0.0
condition 0 3 0.0
subroutine 4 6 66.6
pod 1 1 100.0
total 17 73 23.2


line stmt bran cond sub pod time code
1             # -*- cperl -*-
2             # copyright (C) 2005 Topia . all rights reserved.
3             # This is free software; you can redistribute it and/or modify it
4             # under the same terms as Perl itself.
5             # $Id: OO.pm 110 2005-02-05 10:48:57Z topia $
6             # $URL: file:///usr/minetools/svnroot/mixi/trunk/WWW-Mixi-OO/lib/WWW/Mixi/OO.pm $
7             package WWW::Mixi::OO;
8 3     3   59124 use strict;
  3         8  
  3         117  
9 3     3   14 use warnings;
  3         6  
  3         102  
10 3     3   1150 use WWW::Mixi::OO::Session;
  3         6  
  3         107  
11 3     3   20 use constant session_class => 'WWW::Mixi::OO::Session';
  3         4  
  3         1681  
12             our $VERSION = 0.03;
13              
14             =head1 NAME
15              
16             WWW::Mixi::OO - LWP::UserAgent based Mixi Access Helper Module
17             (WWW::Mixi compatible class)
18              
19             =head1 SYNOPSIS
20              
21             use WWW::Mixi::OO;
22             my $mixi = WWW::Mixi::OO->new('foo@example.com', 'password');
23             $mixi->login;
24             my $res = $mixi->page('home');
25             print $res->content;
26             my @friends = $mixi->page('list_friend')->fetch;
27              
28             =head1 DESCRIPTION
29              
30             mixi (L) is a social network service in Japan.
31              
32             This module provides L compatible interface.
33             use L for real L's interface.
34              
35             =head1 METHODS
36              
37             =over 4
38              
39             =cut
40              
41             # WWW::Mixi's methods
42             # parse_*, get_*
43             # => WWW::Mixi::OO::*, isa WWW::Mixi::OO::Page
44             # rewrite(callback_rewrite), escape, unescape, remove_tag,
45             # convert_login_time, absolute_url
46             # => WWW::Mixi::OO::Util
47             # save_cookies, load_cookies, login, is_logined, is_login_required, session,
48             # new, absolute_linked_url, post, get, set_content
49             # => WWW::Mixi::OO::Session
50             # refresh => not found!
51              
52              
53             =item new
54              
55             my $mixi = WWW::Mixi::OO->new(
56             $email, $password,
57             [-rewrite => \&rewriter]);
58              
59             WWW::Mixi::OO constructor.
60              
61             =cut
62              
63             sub new {
64 0     0 1   my ($class, $email, $password, %opt) = @_;
65              
66             # necessary parameters
67 0 0         Carp::croak('WWW::Mixi mail address required') unless $email;
68 0 0         Carp::croak('WWW::Mixi password required') unless $password;
69 0 0         $opt{rewriter} = delete $opt{-rewrite} if exists $opt{-rewrite};
70              
71 0           my $session = $class->session_class->new(
72             email => $email,
73             password => $password,
74             encoding => 'euc-jp',
75             %opt);
76              
77 0           my $this = {
78             session => $session,
79             };
80              
81 0           bless $this, $class;
82 0           return $this;
83             }
84              
85             sub AUTOLOAD {
86 0     0     my $this = shift;
87 0           my $session = $this->{session};
88 0           our $AUTOLOAD;
89 0           $_ = $AUTOLOAD;
90              
91             # convert name
92 0           s/url/uri/g;
93              
94 0 0 0       if (/^(parse|get)_(calendar)(_[^_]+)?$/ or # calendar & calendar_next
    0          
95             /^(parse|get)_([^_]+_[^_]+)(_[^_]+)?$/) { # foo_bar & ...
96             # parse or get
97 0           my ($main_method, $pagename, $sub_method) = ($1, $2, $3);
98 0 0         $sub_method = '' unless defined $sub_method;
99              
100 0 0         if (@_ > 0) {
101 0 0         if ($main_method eq 'get') {
102 0           my $url = shift;
103 0 0         if ($url eq 'refresh') {
104 0           $session->refresh_content;
105             } else {
106 0           $session->set_content($url);
107             }
108 0           $main_method = 'parse';
109             } else {
110             # has response
111 0           die 'not implemented yet!';
112             }
113             }
114 0 0         if ($sub_method =~ /^(next|previous)$/) {
115             # to navi_{next,prev}
116 0           $sub_method = 'navi_' . substr($sub_method, 0, 4);
117             }
118 0           my $page = $session->page($pagename);
119 0           my $method = "$main_method$sub_method";
120 0           $page->$method(@_);
121             } elsif (/^session$/) {
122 0           $session->session_id(@_);
123             } else {
124             # last resort: send to session
125 0           $session->$_(@_);
126             }
127             }
128              
129             1;
130             __END__