App-Slackeria
view release on metacpan or search on metacpan
lib/App/Slackeria/Plugin/Debian.pm view on Meta::CPAN
package App::Slackeria::Plugin::Debian;
use strict;
use warnings;
use 5.010;
use parent 'App::Slackeria::Plugin';
use LWP::UserAgent;
use XML::LibXML;
our $VERSION = '0.12';
sub new {
my ( $obj, %conf ) = @_;
my $ref = {};
$ref->{default} = \%conf;
$ref->{ua} = LWP::UserAgent->new( timeout => 10 );
return bless( $ref, $obj );
}
sub check {
my ($self) = @_;
my $name = $self->{conf}->{name};
my $dist = $self->{conf}->{distribution} // 'sid';
my $reply = $self->{ua}->get("http://packages.debian.org/${dist}/${name}");
if ( not $reply->is_success ) {
die( $reply->status_line );
}
$self->{conf}->{href} //= 'http://packages.debian.org/sid/%s';
my $href = sprintf( $self->{conf}->{href}, $self->{conf}->{name} );
my $html = $reply->decoded_content();
my $tree = XML::LibXML->load_html(
string => $html,
recover => 2,
suppress_errors => 1,
suppress_warnings => 1,
);
my $xp_title = XML::LibXML::XPathExpression->new('//div[@id="content"]/h1');
my $re_package = qr{
^ Package: \s ${name} \s
\( (?<ver> \S+ )
(?: \) | \s and \s others)
}x;
for my $node ( @{ $tree->findnodes($xp_title) } ) {
my $text = $node->textContent;
if ( $text =~ $re_package ) {
return {
data => $+{ver},
href => $href
};
}
}
die("not found\n");
}
1;
__END__
=head1 NAME
App::Slackeria::Plugin::Debian - Check project version in Debian
=head1 SYNOPSIS
In F<slackeria/config>
[Debian]
=head1 VERSION
version 0.12
=head1 DESCRIPTION
This plugin queries a project and its version in Debian Sid.
=head1 CONFIGURATION
=over
=item distribution
Debian Distribution to check. Defaults to B<sid>.
=item href
( run in 0.443 second using v1.01-cache-2.11-cpan-97f6503c9c8 )