###########################################
package Distro::Plugin::Suse;
###########################################
use Mouse;
extends 'Distro::Plugin::FTP';
use DateTime::Format::Strptime;
use Web::Scraper;
use URI;

sub list {
  my( $self, $query ) = @_;

  my @result = ();
  my $url = "http://download.opensuse.org".
   "/update/openSUSE-current/x86_64/";

  my $rpms = scraper {
      process "pre", "text" => 'TEXT';
  };

  my $html = 
    $rpms->scrape( URI->new( $url ) );
  my $text = $html->{ text };

      # b=28-Nov-2012 c=17:02
  my $f = DateTime::Format::Strptime->new(
      pattern   => "%d-%b-%Y %H:%M",
      time_zone => "UTC",
  );

  while( $text =~ /^\s*(\S+\.rpm)
                    \s+(\d\S+)
                    \s+(\d\S+)
                  /msgx ) {
    my $pkg  = $1;
    my $date = "$2 $3";

    next if $pkg !~ /$query/;

    my $dt = $f->parse_datetime( $date );
    push @result, { 
      pkg => $pkg, mtime => $dt->epoch() };
  }

  return \@result;
}

1;
