+
+# this writes out the filter in a form suitable to be read in by 'read_in'
+# It expects a list of references to filter lines
+sub write
+{
+ my $self = shift;
+ my $sort = $self->{sort};
+ my $name = $self->{name};
+ my $dir = "$filterbasefn/$sort";
+ my $fn = "$dir/$name";
+
+ mkdir $dir, 0775 unless -e $dir;
+ rename $fn, "$fn.o" if -e $fn;
+ my $fh = new IO::File ">$fn";
+ if ($fh) {
+# my $dd = new Data::Dumper([ $self ]);
+# $dd->Indent(1);
+# $dd->Terse(1);
+# $dd->Quotekeys($] < 5.005 ? 1 : 0);
+ # $fh->print($dd->Dumpxs);
+
+ # remove code references, do the encode, then put them back again (they can't be represented anyway)
+ my $key;
+ foreach $key ($self->getfilkeys) {
+ $self->{$key}->{reject}->{code} = undef if exists $self->{$key}->{reject};
+ $self->{$key}->{accept}->{code} = undef if exists $self->{$key}->{accept};
+ }
+ $fh->print($json->encode($self));
+ foreach $key ($self->getfilkeys) {
+ $self->compile($key, 'reject');
+ $self->compile($key, 'accept');
+ }
+ $fh->close;
+ } else {
+ rename "$fn.o", $fn if -e "$fn.o";
+ return "$fn $!";
+ }
+ return undef;
+}
+