Gnus::Newsrc - parse ~/.newsrc.eld files


perl-lisp documentation Contained in the perl-lisp distribution.

Index


Code Index:

NAME

Top

Gnus::Newsrc - parse ~/.newsrc.eld files

SYNOPSIS

Top

  $newsrc = Gnus::Newsrc->new;
  ($level, $read, $marks, $server, $group_para) =
     @{$newsrc->alist_hash->{"comp.lang.perl.misc"}};

DESCRIPTION

Top

The Gnus::Newsrc objects represents the content of the ~/newsrc.eld files that the Gnus newsreader use to store away its state.

The following methods are provided:

$newsrc = Gnus::Newsrc->new( [$filename] )

The object constructor takes an optional filename as argument. The file defaults to ~/.newsrc.eld. It will read and parse the file and return a reference to a Gnus::Newsrc object. The constructor will croak if the file can't be found or can't be parsed.

$newsrc->file_version

Return the version number found in the file (gnus-newsrc-file-version). The version number is a string like "Gnus v5.5".

$newsrc->last_checked_date

Returns a string like "Sat Oct 18 14:05:53 1997" (gnus-newsrc-last-checked-date).

$newsrc->alist

Returns a reference to an array that will have one element for each active newsgroup (gnus-newsrc-alist). Each element is a array with the following values:

   $group_name
   $group_level
   $read_articles
   \%marks
   \@server
   \%group_parameters

The $read_articles and %marks values is a string of integer ranges, and it is suitable for initializing a Set::IntSpan objects.

$newsrc->alist_hash

Returns a reference to a hash indexed by group names. The hash values are the same as the alist elements, but the $group_name is missing.

$newsrc->server_alist

(gnus-server-alist).

$newsrc->killed_list

A reference to an array that contains all the killed newsgroups (gnus-killed-list).

$newsrc->zombie_list

A reference to an array that contains all zombie newsgroups (gnus-zombie-list).

$newsrc->format_specs

SEE ALSO

Top

Set::IntSpan, http://www.gnus.org

COPYRIGHT

Top


perl-lisp documentation Contained in the perl-lisp distribution.
package Gnus::Newsrc;

use strict;
use vars qw($VERSION);

$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);

use Lisp::Reader qw(lisp_read);



sub new
{
    my($class, $file) = @_;
    $file = "$ENV{HOME}/.newsrc.eld" unless defined $file;
    local($/) = undef;  #slurp;
    open(LISP, $file) || die "Can't open $file: $!";
    my $lisp = <LISP>;
    close(LISP);

    local $Lisp::Reader::SYMBOLS_AS_STRINGS = 1;  # gives quicker parsing
    my $form = lisp_read($lisp);

    my $self = bless {}, $class;

    for (@$form) {
	my($one,$two,$three) = @$_;
	#print join(" - ", map {$_->name} $one, $two), "\n";
	if ($one eq "setq") {
	    if (ref($three) eq "ARRAY") {
		my $first = $three->[0];
		if ($first eq "quote") {
		    $three = $three->[1];
		}
	    }
	    $self->{$two} = $three;
	} else {
	    warn "$_ does not start with (setq symbo ...)\n";
	}
    }

    # make the 'gnus-newsrc-alist' into a more perl suitable structure
    for (@{$self->{'gnus-newsrc-alist'}}) {
	my($group, $level, $read, $marks, $server, $para) = @$_;

	for ($read, $marks, $para) {
	    $_ = [] unless defined;
	}
	$_->[2] = join(",", map {ref($_)?"$_->[0]-$_->[1]":$_} @$read);
	$_->[3] = @$marks ?
                     { map {shift(@$_) =>
		            join(",", map {ref($_)?"$_->[0]-$_->[1]":$_}@$_)}
                      @$marks
                     }
                  : undef;
	$_->[5] = @$para ? { map { $_->[0] => $_->[1] } @$para } : undef;

	# trim trailing undef values
	pop(@$_) until defined($_->[-1]) || @$_ == 0;
    }

    $self;
}



sub file_version
{
    shift->{"gnus-newsrc-file-version"};
}



sub last_checked_date
{
    shift->{"gnus-newsrc-last-checked-date"};
}



sub alist
{
    shift->{"gnus-newsrc-alist"};
}



sub alist_hash
{
    my $self = shift;
    unless ($self->{'_alist_hash'}) {
	my %ahash;
	$self->{'_alist_hash'} = \%ahash;
	for (@{$self->alist}) {
	    my @groupinfo = @$_;
	    my $group = shift @groupinfo;
	    $ahash{$group} = \@groupinfo;
	}
    }
    $self->{'_alist_hash'};
}



sub server_alist
{
    shift->{"gnus-server-alist"};

}



sub killed_list
{
    shift->{"gnus-killed-list"};
}



sub zombie_list
{
    shift->{"gnus-zombie-list"};
}



sub format_specs
{
    shift->{"gnus-format-specs"};
}


1;
__END__