aboutsummaryrefslogtreecommitdiff
path: root/Plugin
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-05-07 18:06:17 +1200
committerDavid Phillips <david@sighup.nz>2018-05-07 18:06:17 +1200
commit00f7c03c9ad2e9dddf92f679b0f59c8d6b47a37a (patch)
tree31029107fbd04d58310948cc5959f4b8d7c12273 /Plugin
parentf53e5933315a316bb94d8d27cebbb95554aca6ba (diff)
downloadidalius-00f7c03c9ad2e9dddf92f679b0f59c8d6b47a37a.tar.xz
Replace HTML::HeadParser with HTML::Parser
Weird bugs with HeadParser, cannot debug and patch for upstream as yet
Diffstat (limited to 'Plugin')
-rw-r--r--Plugin/URL_Title.pm22
1 files changed, 17 insertions, 5 deletions
diff --git a/Plugin/URL_Title.pm b/Plugin/URL_Title.pm
index 8248560..5774528 100644
--- a/Plugin/URL_Title.pm
+++ b/Plugin/URL_Title.pm
@@ -5,7 +5,7 @@ package Plugin::URL_Title;
use strict;
use warnings;
use HTTP::Tiny;
-use HTML::HeadParser;
+use HTML::Parser;
use utf8;
my %config;
@@ -18,6 +18,17 @@ sub configure {
return $self;
}
+my $title;
+
+sub start_handler
+{
+ return if shift ne "title";
+ my $self = shift;
+ $self->handler(text => sub { $title = shift; }, "dtext");
+ $self->handler(end => sub { shift->eof if shift eq "title"; },
+ "tagname,self");
+}
+
sub message
{
my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_;
@@ -47,11 +58,12 @@ sub message
my $html = $response->{content};
utf8::decode($html);
- my $parser = HTML::HeadParser->new;
- $parser->parse($html);
+ $title = "";
+ my $p = HTML::Parser->new(api_version => 3);
+ $p->handler( start => \&start_handler, "tagname,self");
+ $p->parse($html);
+ die "Error: $!\n" if $!;
- # get title and unpack from utf8 (assumption)
- my $title = $parser->header("title");
utf8::upgrade($title);
return unless $title;