Acme-Terror-UK

 view release on metacpan or  search on metacpan

lib/Acme/Terror/UK.pm  view on Meta::CPAN

package Acme::Terror::UK;

## Get and return the current UK terrorist threat status.
## Robert Price - http://www.robertprice.co.uk/

use 5.00503;
use strict;

use LWP::Simple;

use vars qw($VERSION);
$VERSION = '0.06';

use constant UNKNOWN		=> 0;
use constant CRITICAL		=> 1;
use constant SEVERE		=> 2;
use constant SUBSTANTIAL	=> 3;
use constant MODERATE		=> 4;
use constant LOW		=> 5;


sub new {
	my ($class, %args) = @_;
	$class = ref($class)	if (ref $class);
	return bless(\%args, $class);
}

sub fetch {
	my $self = shift;
	my $url = 'http://www.mi5.gov.uk/';
	my $html = get($url);
	return undef unless ($html);
	my ($lvl) = ($html =~ m!</a>Current UK threat level</strong></p>.+?<h3><font style="FONT-SIZE: 12pt">(.+?)</font></h3>!sgi);
	return $lvl;
}

sub level {
	my $self = shift;
	my $level = $self->fetch();
	return UNKNOWN	unless ($level);
	if ($level eq 'CRITICAL') {
		return CRITICAL;
	} elsif ($level eq 'SEVERE') {
		return SEVERE;
	} elsif ($level eq 'SUBSTANTIAL') {
		return SUBSTANTIAL;
	} elsif ($level eq 'MODERATE') {
		return MODERATE;
	} elsif ($level eq 'LOW') {
		return LOW;
	} else {
		return UNKNOWN;
	} 	
}


1;
__END__

=head1 NAME

Acme::Terror::UK - Fetch the current UK terror alert level

=head1 SYNOPSIS

  use Acme::Terror::UK;
  my $t = Acme::Terror::UK->new();  # create new Acme::Terror::UK object

  my $level = $t->fetch;
  print "Current terror alert level is: $level\n";

=head1 DESCRIPTION

Gets the currrent terrorist threat level in the UK.

The levels are either...
 CRITICAL - an attack is expected imminently 
 SEVERE - an attack is likely
 SUBSTANTIAL - an attack is a strong possibility
 MODERATE - an attack is possible but not likely
 LOW - an attack is unlikely

This module aims to be compatible with the US version, Acme::Terror

=head1 METHODS



( run in 0.600 second using v1.01-cache-2.11-cpan-5b529ec07f3 )