# -*- mode: Perl; -*-

package NewsClipper::Handler::Acquisition::heisenews;

use vars qw( @ISA $VERSION %handlerInfo );

$handlerInfo{'Author_Name'}              = 'David Coppit';
$handlerInfo{'Author_Email'}             = 'coppit@cs.virginia.edu';
$handlerInfo{'Maintainer_Name'}          = 'David Coppit';
$handlerInfo{'Maintainer_Email'}         = 'coppit@cs.virginia.edu';
$handlerInfo{'Description'}              = <<'EOF';
Heise News Ticker
EOF
$handlerInfo{'Category'}                 = 'News Clipper';
$handlerInfo{'URL'}                      = <<'EOF';
http://www.heise.de/newsticker/
EOF
$handlerInfo{'License'}                  = 'GPL';
$handlerInfo{'For_News_Clipper_Version'} = '1.18';
$handlerInfo{'Language'}                 = 'English';
$handlerInfo{'Notes'}                    = <<'EOF';
based on schema by Andreas Heitmann <aheit@physik.uni-kassel.de>
       In German
EOF
$handlerInfo{'Syntax'}                   = <<'EOF';
<input name=heisenews>
  Returns an array of links
EOF

use strict;
use NewsClipper::Handler;
@ISA = qw(NewsClipper::Handler);

# - The first number should be incremented when a change is made to the
#   handler that will break people's input files.
# - The second number should be incremented when a change is made that won't
#   break people's input files, but changes the functionality.
# - The third number should be incremented when only a bugfix is applied.

$VERSION = do {my @r=('0.81.0'=~/\d+/g);sprintf "%d."."%02d"x$#r,@r};

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

sub ComputeURL
{
  my $self = shift;
  my $attributes = shift;

  my $url = "http://www.heise.de/newsticker/";

  return $url;
}

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

# This subroutine checks the handler's attributes to make sure they are valid,
# and sets any default attributes if necessary.

sub ProcessAttributes
{
  my $self = shift;
  my $attributes = shift;
  my $handlerRole = shift;

  # Set defaults here. You can safely delete this function if your handler has
  # no attributes with default values.

  # $attributes->{'some_attribute'} = 'default_value'
  #   unless defined $attributes->{'some_attribute'};

  # Verify any attributes you need to here. Output an error and return undef
  # if something is wrong.

  # unless ($attributes->{somevalue} > 0)
  # {
  #   error "The \"somevalue\" attribute for handler \"HANDLERNAME\" " .
  #     "should be greater than 0.\n";
  #   return undef;
  # }

  return $attributes;
}

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

# This function is used to get the raw data from the URL.
sub Get
{
  my $self = shift;
  my $attributes = shift;

  my $url = $self->ComputeURL($attributes);

  my $data = &GetLinks($url,
             '\<\/HEISETEXT\>','\<\/td\>');

  return undef unless defined $data;

  return $data;
}

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

sub GetDefaultHandlers
{
  my $self = shift;
  my $inputAttributes = shift;

  my $returnVal =<<'  EOF';
    <filter name='limit' number='10'>
    <output name='array'>
  EOF

  return $returnVal;
}

1;
