The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mail::Freshmeat - class for parsing e-mail newsletters from freshmeat.net

SYNOPSIS

$newsletter = new Mail::Freshmeat( \*STDIN );
$newsletter->parse;

foreach my $entry (@{$newsletter->entries}) {

  print "Name: $entry->{name}";
  print "Version: $entry->{version};
  ...

  # Get an entry line as if it was from the first list
  # in the newsletter
  print $newsletter->short_entry($entry), "\n";

}

DESCRIPTION

A subclass of Mail::Internet.

This package provides parsing of the daily e-mail newsletters which are sent out from http://freshmeat.net/ to any individual who requests them.

METHODS

  • parse

    $newsletter->parse;

    This method must be called before any accessors can be used.

ACCESSORS

  • entry_keys

    my @entry_keys = $newsletter->entry_keys;

    Returns the keys which each entry may have set, in the order in which they are encountered in the newsletter:

    - position
    - name_and_version
    - name
    - version
    - posted_on 
    - license 
    - category 
    - homepage 
    - download 
    - changelog 
    - body_type 
    - body 
    - changes 
    - urgency 
    - url
  • summary

    $summary = $self->summary;

    Returns the paragraph starting 'This is the official freshmeat newsletter ...'.

  • date

    $date = $self->date;

    Returns the date on which this newsletter was released.

  • total

    $total = $self->total;

    Returns the total number of entries in the newsletter.

  • entries

    Returns a reference to an array of hashes, each containing fully parsed information about an entry of the newsletter. The entries are in the original newsletter order.

    The keys of each hash will be a subset of the list returned by the entry_keys method.

  • advertisement

    $ad = $self->advertisement;

    Returns the '[ advertisement ]' section of the newsletter, which has one entry per line.

  • list

    $list = $self->list;

    Returns the '[ article list ]' section of the newsletter, which has one entry per line.

  • footer

    Returns the remainder of the newsletter following the '[ article details ]' section.

  • details

    Returns the '[ article details ]' sections of the newsletter, which has each entry in full.

  • short_entry

    $list1 = $newsletter->list;
    $list2 = join '', map { 'o ' . $newsletter->short_entry($_) . "\n" }
                          @{$newsletter->entries};
    if ($list1 ne $list2) {
      die "Oh no!  Mail::Freshmeat doesn't do what it claims!";
    }

    :-)

    What, that's not real documentation? Bah. Alright then. This method returns the entry in exactly the same format as when it was one of the lines beginning with 'o ' in the original newsletter, minus the actual 'o ' bit. So, you can regenerate the entire '[ article list ]' section (in a new order, if you want) using something similar to the example above.

  • entry_header

    This method returns the entry's "header" (from the line starting 'name:' to the line starting 'changelog:' (or to the line where 'changelog:' would have been if it was there)) in exactly the same format (modulo whitespace) as when it was one of the entries in the '[ article details ]' section of the original newsletter.

  • entry_body

    This method returns the entry's "body" -- everything following the entry's "header" as returned by entry_header.

  • long_entry

    $list1 = $newsletter->details;
    $list2 = join $newsletter->divider,
                  map { $newsletter->long_entry($_) }
                      @{$newsletter->entries};
    
    # $list1 and $list2 should now be identical(ish) modulo whitespace

    This method returns the entry in exactly the same format (modulo whitespace differences) as when it was one of the entries in the '[ article details ]' section of the original newsletter. So, you can regenerate that entire section (in a new order, if you want) using something similar to the example above.

    All this method actually does is concatenate the results of the entry_header and entry_body methods.

  • divider

    print $newsletter->divider;

    Returns one of those fancy

    '--- - --- ------ - --- -- - - - -- -'

    dividers.

  • ad_header

    print $newsletter->ad_header;

    Returns the text for starting the advertisement section.

  • list_header

    print $newsletter->list_header;

    Returns the text for starting the article list section.

  • details_header

    print $newsletter->details_header;

    Returns the text for starting the article details section.

AUTHOR

Adam Spiers <adam@spiers.net>

LICENSE

All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

VERSION

This is release 0.91.

SEE ALSO

perl(1).