Perm/Plugin/IP.pm

filter: Statementstmt 90.4% 19 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 92.8% 26 / 28 CC 1 SCAR 0.4
CC
1
Cov
90%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Perm/Term.pm ↑ Summary
1 package BBS::Perm::Plugin::IP;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Regexp::Common qw/net/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use IP::QQWry;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use Glib qw/TRUE FALSE/;
11 use Encode;
12  
13 my $qqwry = IP::QQWry->new;
14  
15 sub new {
16 my ( $class, %opt ) = @_;
17 $qqwry->set_db( $opt{qqwry} ) if $opt{qqwry};
18 my $widget = $opt{widget} || Gtk2::Statusbar->new;
19 my $id = $widget->get_context_id('ip');
20 my $self = { ip => {} };
21 $self->{widget} = $widget;
22 $self->{_id} = $id;
23 $self->{_encoding} = $opt{encoding} || 'gbk';
24 $self->{_length} = $opt{length} || 80;
25 bless $self, ref $class || $class;
26 }
27  
28 sub add {
29 my ( $self, $input ) = @_;
30 $input =~ s/\*/1/g;
31 return if defined $self->{ip}{$input};
32  
33 my @info;
34 if ( @info = $qqwry->query($input) ) {
35 $self->{ip}{$input} = [@info];
36 }
37 else {
38 $self->{ip}{$input} = [];
39 }
40 }
41  
42 sub remove {
43 my ( $self, $ip ) = @_;
44 delete $self->{ip}{$ip};
45 }
46  
47 sub ip {
48 my $self = shift;
49 return $self->{ip};
50 }
51  
52 sub clear {
53 shift->{ip} = {};
54 }
55  
56 sub show {
57 my $self = shift;
58 my $show = q{};
59  
60 if ( $self->ip ) {
61 for ( sort keys %{ $self->ip } ) {
62 my $info =
63 decode( $self->{_encoding}, join '',
64 grep { $_ } @{ $self->ip->{$_} } )
65 || q{};
66 $show .= $_ . ': ' . $info . "; ";
67 }
68  
69 my $length = $self->{_length};
70 $show = sprintf( "%${length}s", $show );
71 }
72 $self->widget->pop( $self->_id );
73 $self->widget->push( $self->_id, $show );
74 return TRUE;
75 }
76  
77 sub AUTOLOAD {
78 no strict 'refs';
79 our $AUTOLOAD;
80 if ( $AUTOLOAD =~ /.*::(.*)/ ) {
81 my $element = $1;
82 *$AUTOLOAD = sub { return shift->{$element} };
83 goto &$AUTOLOAD;
84 }
85 }
86  
87 sub DESTROY { }
88  
89 1;
90  
91 __END__
« Perm/Term.pm ↑ Summary