File Coverage

blib/lib/POE/Component/Client/Whois/Smart/Cache.pm
Criterion Covered Total %
statement 43 45 95.5
branch 4 8 50.0
condition 3 8 37.5
subroutine 8 10 80.0
pod 0 3 0.0
total 58 74 78.3


line stmt bran cond sub pod time code
1             #
2             #===============================================================================
3             #
4             # FILE: Cache.pm
5             #
6             # DESCRIPTION:
7             #
8             # FILES: ---
9             # BUGS: ---
10             # NOTES: ---
11             # AUTHOR: Pavel Boldin (),
12             # COMPANY:
13             # VERSION: 1.0
14             # CREATED: 14.07.2009 03:52:32 MSD
15             # REVISION: ---
16             #===============================================================================
17              
18             package POE::Component::Client::Whois::Smart::Cache;
19              
20 1     1   1150 use strict;
  1         3  
  1         45  
21 1     1   6 use warnings;
  1         2  
  1         36  
22              
23 1     1   1148 use Data::Dumper;
  1         7341  
  1         86  
24 1     1   1113 use Net::Whois::Raw::Common;
  1         270758  
  1         460  
25              
26             sub initialize {
27             # die "fuck";
28 1     1 0 797 1;
29             }
30              
31             sub query_order {
32 0     0 0 0 0;
33             }
34              
35             sub query {
36 1     1 0 1262 my $class = shift;
37 1         2 my $query_list = shift;
38 1         3 my $heap = shift;
39 1         2 my $args_ref = shift;
40              
41 1         2 my @my_queries;
42              
43 1         4 @$query_list = grep
44 1         2 { ! _check_from_cache( $_, $heap, $args_ref ) } @$query_list;
45              
46             }
47              
48             sub _check_from_cache {
49 1     1   2 my ($q, $heap, $args_ref) = @_;
50              
51             my $result = Net::Whois::Raw::Common::get_from_cache(
52             $q,
53             $heap->{params}->{ cache_dir },
54             $heap->{params}->{ cache_time },
55 1         5 );
56              
57 1 50       467 return unless $result;
58              
59             #warn Dumper $result;
60              
61 1         4 my $request = { %$args_ref };
62              
63 1         2 my @res;
64 1         3 foreach (@$result) {
65 2         9 $_->{server} = delete $_->{srv };
66 2         6 $_->{whois } = delete $_->{text};
67              
68 2         13 my (undef, $error) =
69             Net::Whois::Raw::Common::process_whois(
70             $q,
71             $_->{server},
72             $_->{whois},
73             1
74             );
75              
76 2 50       68098 $_->{error} = $error if $error;
77              
78 2         11 push @res, $_;
79             }
80              
81 1         5 $request->{cache } = \@res;
82 1         5 $request->{from_cache} = 1;
83              
84 1         6 $heap->{result}->{ $q } = \@res;
85              
86 1         17 return 1;
87             }
88              
89              
90             sub _on_done_order {
91 0     0   0 10;
92             }
93              
94             sub _on_done {
95 1     1   23 my $class = shift;
96 1         3 my $heap = shift;
97              
98 1         2 foreach my $query (keys %{$heap->{result}}) {
  1         3  
99              
100 1 50       6 my $num = $heap->{params}->{referral} == 0 ? 0 : -1;
101              
102 1         2 my $result = $heap->{result}{ $query }->[ $num ];
103              
104             #warn $query;
105              
106 1 50 33     22 if ( $heap->{params}->{cache_dir}
      50        
      33        
107             && !$result->{from_cache}
108             && ($result->{server} || '') ne 'directi') {
109 1         7 Net::Whois::Raw::Common::write_to_cache(
110             $query,
111             $heap->{result}->{$query},
112             $heap->{params}->{cache_dir}
113             );
114             }
115             }
116             }
117              
118             1;
119