Acme-Terror-NL

 view release on metacpan or  search on metacpan

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

package Acme::Terror::NL;
use strict;
use LWP::Simple;

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

use constant {
   UNKNOWN        => 0,
   CRITICAL       => 1,
   SUBSTANTIAL    => 2,
   LIMITED        => 3,
   MINIMAL        => 4,
};

sub new {
   my ($class, %args) = @_;
   my $self = {};
   bless $self, $class;
   $self->{_level}     =  UNKNOWN;
   $self->{_level_txt} = "UNKNOWN";
   return $self;
}

sub fetch {
   my $self = shift;
   my $uri  = 'http://english.nctb.nl/';
   my $html = get($uri);
   if($html =~ m!href=".+?current_threat_level.+?"[^>]+>\s*(MINIMAL|LIMITED|SUBSTANTIAL|CRITICAL)</a>!is){
      my $lvl = $1;
      if($constant::declared{__PACKAGE__."::".$lvl}) {
         $self->{_level} = eval $lvl;
         $self->{_level_txt} =  $lvl;
      }
   }
   return $self->{_level_txt};
}

sub text {
   my $self = shift;
   $self->fetch unless($self->{_level});
   return $self->{_level_text};
}

sub level {
   my $self = shift;
   $self->fetch unless($self->{_level});
   return $self->{_level};
}

#-------------------------------------------------------------------#

=head1 NAME

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

=head1 SYNOPSIS

  use Acme::Terror::NL;

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

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

=head1 DESCRIPTION

Gets the currrent terrorist threat level in the Netherlands.

The levels are either...

 CRITICAL    - there are strong indications that an attack will occur 
 SUBSTANTIAL - there is a realistic possibility that an attack will occur
 LIMITED     - it appears that attacks can be prevented.
 MINIMAL     - it is unlikely that attacks are being planned.
 UNKNOWN     - cannot determine threat level

There are "only" four levels present in the Netherlands, unlike, e.g. the
United Kingdom and the United States of America, where there are five.



( run in 2.337 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )