| perl-lisp documentation | Contained in the perl-lisp distribution. |
Gnus::Newsrc - parse ~/.newsrc.eld files
$newsrc = Gnus::Newsrc->new;
($level, $read, $marks, $server, $group_para) =
@{$newsrc->alist_hash->{"comp.lang.perl.misc"}};
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:
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.
Return the version number found in the file
(gnus-newsrc-file-version). The version number is a string like
"Gnus v5.5".
Returns a string like "Sat Oct 18 14:05:53 1997"
(gnus-newsrc-last-checked-date).
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.
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.
(gnus-server-alist).
A reference to an array that contains all the killed newsgroups (gnus-killed-list).
A reference to an array that contains all zombie newsgroups (gnus-zombie-list).
Set::IntSpan, http://www.gnus.org
Copyright 1997 Gisle Aas.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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__