| 1 | package POE::Component::IRC::Plugin::WWW::DoctypeGrabber; | ||||||||||
| 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 | |||||||||||
| 6 | 1 | our $VERSION = '2.001004'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use base 'POE::Component::IRC::Plugin::BasePoCoWrap'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use POE::Component::WWW::DoctypeGrabber; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub _make_default_args { | ||||||||
|
Subroutine
_make_default_args: not called CC=1 SCAR=6.9
| |||||||||||
| 12 | return ( | ||||||||||
| 13 | 0 | response_event => 'irc_doctype_grabber', | |||||||||
| 14 | trigger => qr/^doctype\s+(?=\S)/i, | ||||||||||
| 15 | ); | ||||||||||
| 16 | } | ||||||||||
| 17 | |||||||||||
| 18 | 0 | ▶ | sub _make_poco { | ||||||||
|
Subroutine
_make_poco: not called CC=1 SCAR=6.9
| |||||||||||
| 19 | return POE::Component::WWW::DoctypeGrabber->spawn( | ||||||||||
| 20 | debug => shift->{debug}, | ||||||||||
| 21 | 0 | ); | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub _make_response_message { | ||||||||
|
Subroutine
_make_response_message: not called CC=3 SCAR=24.8
| |||||||||||
| 25 | 0 | my $self = shift; | |||||||||
| 26 | 0 | my $in_ref = shift; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $uri = $self->_prepare_uri( $in_ref->{page} ); | |||||||||
| 29 | |||||||||||
| 30 | 0 | my $prefix = ''; | |||||||||
| 31 | 0 | ▶ | if ( $in_ref->{_type} eq 'public' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | $prefix = (split /!/, $in_ref->{_who})[0] . ', '; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | return $prefix . "[$uri] $in_ref->{error}" | ||||||||||
| 36 | 0 | ▶ | if $in_ref->{error}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | my $out = $self->_prepare_out( $in_ref->{result} ); | |||||||||
| 39 | 0 | return $prefix . "[$uri] $out"; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub _message_into_response_event { 'response' } | ||||||||
|
Subroutine
_message_into_response_event: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _make_poco_call { | ||||||||
|
Subroutine
_make_poco_call: not called CC=1 SCAR=6.9
| |||||||||||
| 45 | 0 | my $self = shift; | |||||||||
| 46 | 0 | my $data_ref = shift; | |||||||||
| 47 | |||||||||||
| 48 | $self->{poco}->grab( { | ||||||||||
| 49 | event => '_poco_done', | ||||||||||
| 50 | page => delete $data_ref->{what}, | ||||||||||
| 51 | 0 | map +( "_$_" => $data_ref->{$_} ), | |||||||||
| 52 | keys %$data_ref, | ||||||||||
| 53 | } | ||||||||||
| 54 | ); | ||||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub _prepare_out { | ||||||||
|
Subroutine
_prepare_out: not called CC=4 SCAR=30.0
| |||||||||||
| 58 | 0 | my ( $self, $result ) = @_; | |||||||||
| 59 | 0 | my @out; | |||||||||
| 60 | 0 | ▶ | push @out, length $result->{doctype} ? $result->{doctype} : 'NO DOCTYPE'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | if ( $result->{xml_prolog} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | push @out, "+ $result->{xml_prolog} XML prolog"; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if ( $result->{non_white_space} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | push @out, "+ $result->{non_white_space} non-whitespace characters"; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 0 | push @out, "($result->{mime})"; | |||||||||
| 71 | |||||||||||
| 72 | 0 | return join ' ', @out; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | sub _prepare_uri { | ||||||||
|
Subroutine
_prepare_uri: not called CC=2 SCAR=17.9
| |||||||||||
| 76 | 0 | my ( $self, $uri ) = @_; | |||||||||
| 77 | |||||||||||
| 78 | 0 | $uri =~ s# ^ (?: (?: ht | f )tps?:// (www\.)? | www\. )##xi; | |||||||||
| 79 | 0 | $uri =~ s# \. (?: s?html? | php | pl | asp | jsp | css | js ) $ ##xi; | |||||||||
| 80 | 0 | ▶ | if ( length $uri > 16 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | $uri = substr( $uri, 0, 8) . "..." . substr $uri, -5 ; | |||||||||
| 82 | } | ||||||||||
| 83 | 0 | return $uri; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 1 | 1; | |||||||||
| 87 | __END__ | ||||||||||