/usr/share/perl5/News/Newsrc.pm is in libnews-newsrc-perl 1.09-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | use 5;
use strict;
use integer;
use Set::IntSpan;
package News::Newsrc;
$News::Newsrc::VERSION = 1.09;
$Set::IntSpan::Empty_String = '';
sub new
{
my ($class, $file, %options) = @_;
my $newsrc = { group => {},
list => [] };
bless $newsrc, ref $class || $class;
$newsrc->load($file) or $options{create} or die "Can't load $file: $!\n" if $file;
return $newsrc;
}
sub load
{
my($newsrc, $file) = @_;
$file or $file = "$ENV{HOME}/.newsrc";
$newsrc->{file } = $file;
$newsrc->{group} = { };
$newsrc->{list } = [ ];
open(NEWSRC, $file) or return '';
my $lines = [ <NEWSRC> ]; # whole file
close(NEWSRC);
eval { $newsrc->import_rc($lines) };
$@ and die "News::Newsrc::load: file $file: $@";
1
}
sub _scan # Initializes a Newsrc object from a string. Used for testing.
{
my($newsrc, $lines) = @_;
my @lines = split /\n/, $lines;
$newsrc->import_rc(@lines);
}
sub import_rc
{
my $newsrc = shift;
my $lines = ref $_[0] ? $_[0] : [ @_ ];
$newsrc->{group} = { };
$newsrc->{list } = [ ];
my $line_number = 1;
for my $line (@$lines)
{
eval { $newsrc->parse($line) };
$@ and die "News::Newsrc::import_rc: line $line_number: $@";
$line_number++;
}
}
sub parse # parses a single line from a newsrc file
{
my($newsrc, $line) = @_;
$line =~ /\S/ or return;
$line =~ s/\s//g;
$line =~ /^ ([^!:]+) ([!:]) (.*) $/x or
die "News::Newsrc::parse: Bad newsrc line: $line";
my($name, $mark, $articles) = ($1, $2, $3);
valid Set::IntSpan $articles or
die "News::Newsrc::parse: Bad article list: $line";
my $group = { name => $name,
subscribed => $mark eq ':',
articles => Set::IntSpan->new($articles) };
$newsrc->{group}{$name} = $group;
push(@{$newsrc->{list}}, $group);
}
sub save
{
my $newsrc = shift;
$newsrc->{file} or $newsrc->{file} = "$ENV{HOME}/.newsrc";
$newsrc->save_as($newsrc->{file});
}
sub save_as
{
my($newsrc, $file) = @_;
-e $file and
(rename($file, "$file.bak") or
die "News::Newsrc::save_as: Can't rename $file, $file.bak: $!\n");
open(NEWSRC, "> $file") or
die "News::Newsrc::save_as: Can't open $file: $!\n";
$newsrc->{file} = $file;
eval { $newsrc->format($file) };
close NEWSRC;
die $@ if $@;
}
sub format
{
my($newsrc, $file) = @_;
for my $group (@{$newsrc->{list}})
{
my $name = $group->{name};
my $sub = $group->{subscribed} ? ':' : '!';
my $articles = $group->{articles}->run_list;
my $space = $articles ? ' ' : '';
print NEWSRC "$name$sub$space$articles\n" or
die "News::Newsrc::format: Can't write $file: $!\n";
}
}
sub export_rc
{
my $newsrc = shift;
my @lines = map { my $group = $_;
my $name = $group->{name};
my $sub = $group->{subscribed} ? ':' : '!';
my $articles = $group->{articles}->run_list;
my $space = $articles ? ' ' : '';
"$name$sub$space$articles\n" } @{$newsrc->{list}};
wantarray ? @lines : \@lines
}
sub _dump # Formats a Newsrc object to a string. Used for testing
{
my $newsrc = shift;
my $dump = '';
for my $group (@{$newsrc->{list}})
{
my $name = $group->{name};
my $sub = $group->{subscribed} ? ':' : '!';
my $articles = $group->{articles}->run_list;
$articles = ' ' . $articles if $articles =~ /^\d/;
$dump .= "$name$sub$articles\n";
}
$dump
}
sub add_group
{
my($newsrc, $name, %options) = @_;
if ($newsrc->{group}{$name})
{
$options{replace} or return 0;
$newsrc->del_group($name);
}
my $group = { name => $name,
subscribed => 1,
articles => Set::IntSpan->new };
$newsrc->{group}{$name} = $group;
$newsrc->_insert($group, %options);
1
}
sub move_group
{
my($newsrc, $name, %options) = @_;
my $group = $newsrc->{group}{$name};
$group or return 0;
$newsrc->{list} = [ grep { $_->{name} ne $name } @{$newsrc->{list}} ];
$newsrc->_insert($group, %options);
1
}
sub Splice(\@$$@)
{
my($array, $offset, $length, @list) = @_;
$offset > @$array and $offset = @$array;
$offset < -@$array and $offset = -@$array;
splice @$array, $offset, $length, @list;
}
sub _insert
{
my($newsrc, $group, %options) = @_;
my $list = $newsrc->{list};
my($where, $arg) = ('', '');
$options{where} and $where = $options{where};
ref $where and ($where, $arg) = @$where;
for ($where)
{
/first/ and unshift @$list, $group;
/last/ and push @$list, $group;
/^$/ and push @$list, $group; # default
/alpha/ and Alpha ($list, $group);
/before/ and Before ($list, $group, $arg);
/after/ and After ($list, $group, $arg);
/number/ and Splice @$list, $arg, 0, $group;
}
}
sub Alpha
{
my($list, $group, $before) = @_;
my $name = $group->{name};
for my $i (0..$#$list)
{
if ($name lt $list->[$i]{name})
{
splice @$list, $i, 0, $group;
return;
}
}
push @$list, $group;
}
sub Before
{
my($list, $group, $before) = @_;
my $name = $group->{name};
for my $i (0..$#$list)
{
if ($list->[$i]{name} eq $before)
{
splice @$list, $i, 0, $group;
return;
}
}
push @$list, $group;
}
sub After
{
my($list, $group, $after) = @_;
my $name = $group->{name};
for my $i (0..$#$list)
{
if ($list->[$i]{name} eq $after)
{
splice @$list, $i+1, 0, $group;
return;
}
}
push @$list, $group;
}
sub del_group
{
my($newsrc, $name) = @_;
$newsrc->{group}{$name} or return 0;
delete $newsrc->{group}{$name};
$newsrc->{list} = [ grep { $_->{name} ne $name } @{$newsrc->{list}} ];
1
}
sub subscribe
{
my($newsrc, $name, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{subscribed} = 1;
}
sub unsubscribe
{
my($newsrc, $name, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{subscribed} = 0;
}
sub mark
{
my($newsrc, $name, $article, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{articles}->insert($article);
}
sub mark_list
{
my($newsrc, $name, $list, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my $group = $newsrc->{group}{$name};
my $articles = union { $group->{articles} } $list;
$group->{articles} = $articles;
}
sub mark_range
{
my($newsrc, $name, $from, $to, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my $group = $newsrc->{group}{$name};
my $range = new Set::IntSpan "$from-$to";
my $articles = union { $group->{articles} } $range;
$group->{articles} = $articles;
}
sub unmark
{
my($newsrc, $name, $article, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{articles}->remove($article);
}
sub unmark_list
{
my($newsrc, $name, $list, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my $group = $newsrc->{group}{$name};
my $articles = diff { $group->{articles} } $list;
$group->{articles} = $articles;
}
sub unmark_range
{
my($newsrc, $name, $from, $to, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my $group = $newsrc->{group}{$name};
my $range = new Set::IntSpan "$from-$to";
my $articles = diff { $group->{articles} } $range;
$group->{articles} = $articles;
}
sub exists
{
my($newsrc, $name) = @_;
$newsrc->{group}{$name} ? 1 : ''
}
sub subscribed
{
my($newsrc, $name) = @_;
$newsrc->exists($name) and $newsrc->{group}{$name}{subscribed}
}
sub marked
{
my($newsrc, $name, $article) = @_;
$newsrc->exists($name) and
member { $newsrc->{group}{$name}{articles} } $article
}
sub num_groups
{
my $newsrc = shift;
my $list = $newsrc->{list};
scalar @$list
}
sub groups
{
my $newsrc = shift;
my $list = $newsrc->{list};
my @list = map { $_->{name} } @$list;
wantarray ? @list : \@list;
}
sub sub_groups
{
my $newsrc = shift;
my $list = $newsrc->{list};
my @list = map { $_->{name} } grep { $_->{'subscribed'} } @$list;
wantarray ? @list : \@list;
}
sub unsub_groups
{
my $newsrc = shift;
my $list = $newsrc->{list};
my @list = map { $_->{name} } grep { not $_->{'subscribed'} } @$list;
wantarray ? @list : \@list;
}
sub marked_articles
{
my($newsrc, $name, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my @marked = elements { $newsrc->{group}{$name}{articles} };
wantarray ? @marked : \@marked
}
sub unmarked_articles
{
my($newsrc, $name, $from, $to, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
my $range = new Set::IntSpan "$from-$to";
my $unmarked = diff $range $newsrc->{group}{$name}{articles};
my @unmarked = elements $unmarked;
wantarray ? @unmarked : \@unmarked
}
sub get_articles
{
my($newsrc, $name, %options) = @_;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{articles}->run_list;
}
sub set_articles
{
my($newsrc, $name, $articles, %options) = @_;
valid Set::IntSpan $articles or return 0;
my $set = new Set::IntSpan $articles;
finite $set or return 0;
my $min = $set->min;
defined $min and $min < 0 and return 0;
$newsrc->{group}{$name} or $newsrc->add_group($name, %options);
$newsrc->{group}{$name}{articles} = $set;
1
}
1
__END__
=head1 NAME
News::Newsrc - manage newsrc files
=head1 SYNOPSIS
use News::Newsrc;
$newsrc = new News::Newsrc;
$newsrc = new News::Newsrc $file;
$newsrc = new News::Newsrc $file, create => 1;
$ok = $newsrc->load;
$ok = $newsrc->load ( $file);
$newsrc->import_rc ( @lines);
$newsrc->import_rc (\@lines);
$newsrc->save;
$newsrc->save_as ($file);
@lines = $newsrc->export_rc;
$ok = $newsrc-> add_group ($group, %options);
$ok = $newsrc->move_group ($group, %options);
$ok = $newsrc-> del_group ($group);
$newsrc-> subscribe ($group, %options);
$newsrc->unsubscribe ($group, %options);
$newsrc->mark ($group, $article , %options);
$newsrc->mark_list ($group, \@articles, %options);
$newsrc->mark_range ($group, $from, $to, %options);
$newsrc->unmark ($group, $article , %options);
$newsrc->unmark_list ($group, \@articles, %options);
$newsrc->unmark_range ($group, $from, $to, %options);
... if $newsrc->exists ($group);
... if $newsrc->subscribed ($group);
... if $newsrc->marked ($group, $article);
$n = $newsrc-> num_groups;
@groups = $newsrc-> groups;
@groups = $newsrc-> sub_groups;
@groups = $newsrc->unsub_groups;
@articles = $newsrc-> marked_articles($group, %options);
@articles = $newsrc->unmarked_articles($group, $from, $to, %options);
$articles = $newsrc->get_articles ($group, %options);
$ok = $newsrc->set_articles ($group, $articles, %options);
=head1 REQUIRES
Perl 5.6.0, Set::IntSpan 1.07
=head1 EXPORTS
Nothing
=head1 DESCRIPTION
C<News::Newsrc> manages newsrc files, of the style
alt.foo: 1-21,28,31-34
alt.bar! 3,5,9-2900,2902
Methods are provided for
=over 4
=item *
reading and writing newsrc files
=item *
adding and removing newsgroups
=item *
changing the order of newsgroups
=item *
subscribing and unsubscribing from newsgroups
=item *
testing whether groups exist and are subscribed
=item *
marking and unmarking articles
=item *
testing whether articles are marked
=item *
returning lists of newsgroups
=item *
returning lists of articles
=back
=head1 NEWSRC FILES
A newsrc file is an ASCII file that lists newsgroups and article numbers.
Each line of a newsrc file describes a single newsgroup.
Each line is divided into three fields:
a I<group>, a I<subscription mark> and an I<article list>.
Lines containing only whitespace are ignored.
Whitespace within a line is ignored.
=over 4
=item Group
The I<group> is the name of the newsgroup.
A group name may not contain colons (:) or exclamation points (!).
Group names must be unique within a newsrc file.
The group name is required.
=item Subscription mark
The I<subscription mark> is either a colon (:), for subscribed groups,
or an exclamation point (!), for unsubscribed groups.
The subscription mark is required.
=item Article list
The I<article list> is a comma-separated list of positive integers.
The integers must be listed in increasing order.
Runs of consecutive integers may be abbreviated a-b,
where a is the first integer in the run and b is the last.
The article list may be empty.
=back
=head1 NEWSGROUP ORDER
C<News::Newsrc> preserves the order of newsgroups in a newsrc file:
if a file is loaded and then saved,
the newsgroup order will be unchanged.
Methods that add or move newsgroups affect the newsgroup order.
By default,
these methods put newsgroups at the end of the newsrc file.
Other locations may be specified by passing an I<%options> hash
with a C<where> key to the method.
Recognized locations are:
=over 4
=item C<where> => C<'first'>
Put the newsgroup first.
=item C<where> => C<'last'>
Put the newsgroup last.
=item C<where> => C<'alpha'>
Put the newsgroup in alphabetical order.
If the other newsgroups are not sorted alphabetically,
put the group at an arbitrary location.
=item C<where> => [ C<before> => I<$group> ]
Put the group immediately before I<$group>.
If I<$group> does not exist,
put the group last.
=item C<where> => [ C<after> => I<$group> ]
Put the group immediately after I<$group>.
If I<$group> does not exist,
put the group last.
=item C<where> => [ C<number> => I<$n> ]
Put the group at position I<$n> in the group list.
Indices are zero-based.
Negative indices count backwards from the end of the list.
=back
=head1 METHODS
=over 4
=item I<$newsrc> = C<new> C<News::Newsrc>
=item I<$newsrc> = C<new> C<News::Newsrc> I<$file>, I<%options>
Creates and returns a C<News::Newsrc> object.
If I<$file> is specified,
C<new> loads the newsgroups in I<$file> into the object.
Subsequent calls to C<save> will write to I<$file>.
If I<$file> exists and the load fails, C<new> C<die>s.
If I<$file> doesn't exist and the C<< create => 1 >> option is supplied in I<%options>,
then C<new> doesn't load any newsgroups.
If I<$file> doesn't exist and the C<< create => 1 >> option is not supplied in I<%options>,
then C<new> dies.
=item I<$ok> = I<$newsrc>->C<load>
=item I<$ok> = I<$newsrc>->C<load>(I<$file>)
Loads the newsgroups in I<$file> into I<$newsrc>.
If I<$file> is omitted, reads F<$ENV{HOME}/.newsrc>.
Any existing data in I<$newsrc> is discarded.
Returns true on success.
If I<$file> can't be opened,
C<load> discards existing data from I<$newsrc> and returns null.
If I<$file> contains invalid lines, C<load> will C<die>.
When this happens, the state of I<$newsrc> is undefined.
=item I<$newsrc>->C<import_rc>(I<@lines>)
=item I<$newsrc>->C<import_rc>([I<@lines>])
Imports the newsgroups in I<@lines> into I<$newsrc>.
Any existing data in I<$newsrc> is discarded.
Each line in I<@lines> describes a single newsgroup,
and must have the format described in L<"NEWSRC FILES">.
If I<@lines> contains invalid lines, C<import_rc> will C<die>.
When this happens, the state of I<$newsrc> is undefined.
C<import_rc> accepts either an array or an array reference.
=item I<$newsrc>->C<save>
Writes the contents of I<$newsrc> back to the file
from which it was C<load>ed.
If C<load> has not been called, writes to F<$ENV{HOME}/.newsrc>.
In either case, if the destination I<file> exists,
it is renamed to I<file>C<.bak>.
C<save> will C<die> if there is an error writing the file.
=item I<$newsrc>->C<save_as>(I<$file>)
Writes the contents of I<$newsrc> to I<$file>.
If I<$file> exists, it is renamed to I<$file>C<.bak>.
Subsequent calls to C<save> will write to I<$file>.
C<save_as> will C<die> if there is an error writing the file.
=item I<@lines> = I<$newsrc>->C<export_rc>
Returns the contents of I<$newsrc> as a list of lines.
Each line describes a single newsgroup,
and has the format described in L<"NEWSRC FILES">.
In scalar context, returns an array reference.
=item I<$ok> = I<$newsrc>->C<add_group>(I<$group>, I<%options>)
Adds I<$group> to the list of newsgroups in I<$newsrc>.
I<$group> is initially subscribed.
The article list for I<$group> is initially empty.
By default,
I<$group> is added to the end of the list of newsgroups.
Other locations may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
By default,
C<add_group> does nothing if I<$group> already exists.
If the C<replace> => C<1> option is provided,
then C<add_group> will delete I<$group> if it exists,
and then add it.
C<add_group> returns true iff I<$group> was added.
=item I<$ok> = I<$newsrc>->C<move_group>(I<$group>, I<%options>)
Changes the position of I<$group> in I<$newsrc>
according to I<%options>.
See L<"NEWSGROUP ORDER"> for details.
If I<$group> does not exist,
C<move_group> does nothing and returns false.
Otherwise, it returns true.
=item I<$ok> = I<$newsrc>->C<del_group>(I<$group>)
If I<$group> exists in I<$newsrc>,
C<del_group> removes it and returns true.
The article list for I<$group> is lost.
If I<$group> does not exist in I<$newsrc>,
C<del_group> does nothing and returns false.
=item I<$newsrc>->C<subscribe>(I<$group>, I<%options>)
Subscribes to I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<unsubscribe>(I<$group>, I<%options>)
Unsubscribes from I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<mark>(I<$group>, I<$article>, I<%options>)
Adds I<$article> to the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<mark_list>(I<$group>, I<\@articles>, I<%options>)
Adds I<@articles> to the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<mark_range>(I<$group>, I<$from>, I<$to>, I<%options>)
Adds all the articles from I<$from> to I<$to>, inclusive,
to the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<unmark>(I<$group>, I<$article>, I<%options>)
Removes I<$article> from the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<unmark_list>(I<$group>, I<\@articles>, I<%options>)
Removes I<@articles> from the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<unmark_range>(I<$group>, I<$from>, I<$to>, I<%options>)
Removes all the articles from I<$from> to I<$to>, inclusive,
from the article list for I<$group>.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$newsrc>->C<exists>(I<$group>)
Returns true iff I<$group> exists in I<$newsrc>.
=item I<$newsrc>->C<subscribed>(I<$group>)
Returns true iff I<$group> exists and is subscribed.
=item I<$newsrc>->C<marked>(I<$group>, I<$article>)
Returns true iff I<$group> exists and its article list contains I<$article>.
=item I<$n> = I<$newsrc>->C<num_groups>
Returns the number of groups in I<$newsrc>.
=item I<@groups> = I<$newsrc>->C<groups>
Returns the list of groups in I<$newsrc>,
in newsrc order.
In scalar context, returns an array reference.
=item I<@groups> = I<$newsrc>->C<sub_groups>
Returns the list of subscribed groups in I<$newsrc>,
in newsrc order.
In scalar context, returns an array reference.
=item I<@groups> = I<$newsrc>->C<unsub_groups>
Returns the list of unsubscribed groups in I<$newsrc>,
in newsrc order.
In scalar context, returns an array reference.
=item I<@articles> = I<$newsrc>->C<marked_articles>(I<$group>)
Returns the list of articles in the article list for I<$group>.
In scalar context, returns an array reference.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<@articles> = I<$newsrc>->C<unmarked_articles>(I<$group>, I<$from>, I<$to>, I<%options>)
Returns the list of articles from I<$from> to I<$to>, inclusive,
that do B<not> appear in the article list for I<$group>.
In scalar context, returns an array reference.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
=item I<$articles> = I<$newsrc>->C<get_articles>(I<$group>, I<%options>)
Returns the article list for I<$group> as a string,
in the format described in L<"NEWSRC FILES">.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
If you plan to do any nontrivial processing on the article list,
consider converting it to a C<Set::IntSpan> object:
$articles = Set::IntSpan->new($newsrc->get_articles('alt.foo'))
=item I<$ok> = I<$newsrc>->C<set_articles>(I<$group>, I<$articles>, I<%options>)
Sets the article list for $group.
Any existing article list is lost.
I<$articles> is a string,
as described in L<"NEWSRC FILES">.
I<$group> will be created if it does not exist.
Its location may be specified in I<%options>;
see L<"NEWSGROUP ORDER"> for details.
If I<$articles> does not have the format described in L<"NEWSRC FILES">,
C<set_articles> does nothing and returns false.
Otherwise, it returns true.
=back
=head1 DIAGNOSTICS
=over 4
=item Bad newsrc line
A line in the newsrc file does not have the format described in
L<"NEWSRC FILES">.
=item Bad article list
The article list for a newsgroup does not have the format described in
L<"NEWSRC FILES">.
=item News::Newsrc::save_as: Can't rename $file, $file.bak: $!
=item News::Newsrc::save_as: Can't open $file: $!
=item News::Newsrc::format: Can't write $file: $!
=back
=head1 NOTES
=head2 Error Handling
"Don't test for errors that you can't handle."
C<load> returns null if it can't open the newsrc file,
and dies if the newsrc file contains invalid data.
This isn't as schizophrenic as it seems.
There are several ways a program could handle an open failure on the newsrc file.
It could prompt the user to reenter the file name.
It could assume that the user doesn't have a newsrc file yet.
If it doesn't want to handle the error, it could go ahead and die.
On the other hand,
it is very difficult for a program to do anything sensible
if the newsrc file opens successfully
and then turns out to contain invalid data.
Was there a disk error?
Is the file corrupt?
Did the user accidentally specify his kill file instead of his newsrc file?
And what are you going to do about it?
Rather than try to handle an error like this,
it's probably better to die and let the user sort things out.
By the same rational,
C<save> and C<save_as> die on failure.
Programs that must retain control can use eval{...}
to protect calls that may die.
For example, Perl/Tk runs all callbacks inside an eval{...}.
If a callback dies,
Perl/Tk regains control and displays $@ in a dialog box.
The user can then decide whether to continue or quit from the program.
=head2 C<import_rc>/C<export_rc>
I was going to call these methods C<import> and C<export>,
but C<import> turns out not to be a good name for a method,
because C<use> also calls C<import>,
and expects different semantics.
I added the C<_rc> suffix to C<import> to avoid this conflict.
It's reasonably short and somewhat mnemonic
(the module manages newsI<rc> files).
I added the same suffix to C<export> for symmetry.
=head1 ACKNOWLEDGMENTS
=over 4
=item *
Neil Bowers <neilb@cre.canon.co.uk>
=item *
Matthew Darwin <matthew@davin.ottawa.on.ca>
=item *
Philip Hallstrom <philip.hallstrom@cendantsoft.com>
=item *
M. Hedlund <hedlund@best.com>
=item *
Bruce J. Keeler <bruce@gridpoint.com>
=item *
Chris Leach <Chris.Leach@epa.ericsson.se>
=item *
Abhijit Menon-Sen <ams@wiw.org>
=item *
J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net>
=item *
Lars Balker Rasmussen <gnort@daimi.aau.dk>
=item *
Mike Stok <mike@stok.co.uk>
=item *
Bennett Todd <bet@onyx.interactive.net>
=item *
Larry W. Virden <lvirden@cas.org>
=item *
Chris Szurgot <szurgot@itribe.net>
=back
=head1 AUTHOR
Steven McDougall, swmcd@world.std.com
=head1 SEE ALSO
perl(1), Set::IntSpan
=head1 COPYRIGHT
Copyright 1996-2007 by Steven McDougall. This module is free
software; you can redistribute it and/or modify it under the same
terms as Perl itself.
=cut
|