Webqq/Client/Plugin/CpanRecentModule.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 77 CC 9 SCAR 40.0
CC
9
Cov
0%
call
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 54.8
1 package Webqq::Client::Plugin::CpanRecentModule;
2 use AE;
3 use Encode;
4 use XML::Simple;
5 use POSIX qw(mktime);
6 use Storable qw(store retrieve);
7 use Webqq::Client::Util qw(console);
8 my %data;
9 sub call{
10 my $client = shift;
11 my $path = shift;
12 $client->{watchers}{rand()} = AE::timer 600,600,sub{
13 print "GET https://metacpan.org/feed/recent?f=n\n" if $client->{debug};
14 $client->{asyn_ua}->get('https://metacpan.org/feed/recent?f=n',(),sub{
15 my $res = shift;
16 return unless $res->is_success;
17 my $xml;
18 eval{
19 $xml = XMLin($res->content,KeepRoot=>1);
20 };
21 if($@){
22 console "[Webqq::Client::Plugin::CpanRecentModule]$@\n" if $client->{debug};
23 return;
24 }
25 unless(%data){
26 for my $item (@{ $xml->{'rdf:RDF'}{item} } ){
27 $data{$item->{title}} = {
28 author => $item->{'dc:creator'},
29 'link' => $item->{'link'},
30 desc => $item->{'description'},
31 date => $item->{'dc:date'},
32 };
33 }
34 }
35 else{
36 my @module;
37 for my $item (@{ $xml->{'rdf:RDF'}{item} } ){
38 next if exists $data{$item->{title}};
39 my $link = $client->get_dwz($item->{'link'});
40 $link = $item->{'link'} unless defined $link;
41 push @module,{
42 author => $item->{'dc:creator'},
43 name => $item->{title},
44 'link' => $link,
45 desc => $item->{description},
46 };
47 $data{$item->{title}} = {
48 author => $item->{'dc:creator'},
49 'link' => $item->{'link'},
50 desc => $item->{'description'},
51 date => $item->{'dc:date'},
52 };
53 }
54
55 if(@module){
56 my @msg;
57 for(@module){
58 push @msg ,
59 "模块:$_->{name}\n" .
60 "描述:$_->{desc}\n" .
61 "链接: $_->{link}\n"
62 ;
63 }
64 my $msg = "Hi, CPAN有新模块发布:\n" . join("\n",@msg);
65 $msg = encode("utf8",$msg);
66 for my $g (@{ $client->{qq_database}{group} }){
67 $client->send_group_message(to_uin=>$g->{ginfo}{gid},content=>$msg);
68 }
69 }
70 }
71 });
72 };
73 }
74  
75 1;