| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::FC2::SpamAPI::Response; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 43399 | use warnings; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 113 |  | 
| 4 | 3 |  |  | 3 |  | 18 | use strict; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 241 |  | 
| 5 | 3 |  |  | 3 |  | 24 | use base qw/ Class::Accessor::Fast /; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 1195 |  | 
| 6 | 3 |  |  | 3 |  | 18663 | use Encode qw/ decode encode /; | 
|  | 3 |  |  |  |  | 49689 |  | 
|  | 3 |  |  |  |  | 1791 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | my $Encoding = 'Shift_JIS'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | __PACKAGE__->mk_accessors( | 
| 11 |  |  |  |  |  |  | qw/ is_spam error_message usid name url | 
| 12 |  |  |  |  |  |  | comment category registered_date updated_date / ); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 NAME | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | WebService::FC2::SpamAPI::Response - Reponse object of WebService::FC2::SpamAPI | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 VERSION | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | Version 0.01 | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =cut | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | $res = $api->check_url({ url => $url, data => 1 }); | 
| 29 |  |  |  |  |  |  | $res->is_spam;         # 1 or 0 | 
| 30 |  |  |  |  |  |  | $res->usid;            # fc2 user id | 
| 31 |  |  |  |  |  |  | $res->name;            # site name | 
| 32 |  |  |  |  |  |  | $res->url;             # site url | 
| 33 |  |  |  |  |  |  | $res->comment;         # comment | 
| 34 |  |  |  |  |  |  | $res->category;        # category | 
| 35 |  |  |  |  |  |  | $res->registered_date; # registered date | 
| 36 |  |  |  |  |  |  | $res->updated_date;    # updated date | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 FUNCTIONS | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =head2 parse | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | Parse single response message & returns Response object. | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | =cut | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub parse { | 
| 47 | 5 |  |  | 5 | 1 | 2628 | my ( $class, $content ) = @_; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 5 | 100 |  |  |  | 34 | if ( $content =~ /^True/ ) { # not spam | 
| 50 | 3 |  |  |  |  | 35 | return $class->new({ is_spam => 0 }); | 
| 51 |  |  |  |  |  |  | } | 
| 52 | 2 | 100 |  |  |  | 14 | if ( $content =~ /^False/ ) { # spam & no data | 
| 53 | 1 |  |  |  |  | 19 | return $class->new({ is_spam => 1 }); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 1 |  |  |  |  | 18 | my @res = split /\r*\n/, $content; | 
| 57 | 1 |  |  |  |  | 4 | for my $res ( @res ) { | 
| 58 | 7 |  |  |  |  | 13156 | $res = decode( $Encoding, $res ); | 
| 59 |  |  |  |  |  |  | } | 
| 60 | 1 | 50 |  |  |  | 47 | unless ( $res[0] =~ /\A\d+\z/ ) { # error | 
| 61 | 0 |  |  |  |  | 0 | return $class->new({ is_spam => 0, error_message => $res[0] }); | 
| 62 |  |  |  |  |  |  | } | 
| 63 | 1 |  |  |  |  | 22 | return $class->new({ | 
| 64 |  |  |  |  |  |  | is_spam         => 1, | 
| 65 |  |  |  |  |  |  | usid            => $res[0], | 
| 66 |  |  |  |  |  |  | name            => $res[1], | 
| 67 |  |  |  |  |  |  | url             => $res[2], | 
| 68 |  |  |  |  |  |  | comment         => $res[3], | 
| 69 |  |  |  |  |  |  | category        => $res[4], | 
| 70 |  |  |  |  |  |  | registered_date => $res[5], | 
| 71 |  |  |  |  |  |  | updated_date    => $res[6], | 
| 72 |  |  |  |  |  |  | }); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head2 parse_list | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | Parse multiple response message & returns Response object list. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =cut | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub parse_list { | 
| 82 | 2 |  |  | 2 | 1 | 5086 | my ( $class, $content ) = @_; | 
| 83 | 2 |  |  |  |  | 7 | my @r_list; | 
| 84 | 2 |  |  |  |  | 24 | for my $line ( split /\r*\n/, $content ) { | 
| 85 | 3 | 100 |  |  |  | 170 | if ( $line =~ /\t/ ) { | 
| 86 | 2 |  |  |  |  | 8 | $line = decode( $Encoding, $line ); | 
| 87 | 2 |  |  |  |  | 72 | my @data = split /\t/, $line; | 
| 88 | 2 |  |  |  |  | 18 | push @r_list, $class->new({ | 
| 89 |  |  |  |  |  |  | is_spam         => 1, | 
| 90 |  |  |  |  |  |  | name            => $data[0], | 
| 91 |  |  |  |  |  |  | url             => $data[1], | 
| 92 |  |  |  |  |  |  | registered_date => $data[2], | 
| 93 |  |  |  |  |  |  | }); | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | } | 
| 96 | 2 |  |  |  |  | 45 | return @r_list; | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head1 AUTHOR | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | FUJIWARA Shunichiro, C<<  >> | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | L, http://seo.fc2.com/spam/ | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | Copyright 2007 FUJIWARA Shunichiro, all rights reserved. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 112 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =cut | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | 1; # End of WebService::FC2::SpamAPI |