--- Divert.pm 2003/05/23 20:37:32 1.3
+++ Divert.pm 2003/05/29 18:43:50 1.4
@@ -40,7 +40,7 @@
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(new destroy DESTROY
- name overwrite
+ name overwrite storage
assign append string bool
fold unfold folding folder
divert undivert diversion
@@ -56,6 +56,7 @@
$self->{name} = (defined($name) ? $name : '');
$self->{overwrite} = 'none';
+ $self->{storage} = 'all';
$self->{chunks} = [ '' ];
$self->{diversion} = [];
$self->{foldermk} = '{#%s#}';
@@ -103,6 +104,20 @@
return $old_mode;
}
+# operation: set/get storage mode
+sub storage ($;$) {
+ my ($self, $mode) = @_;
+ return $self->{diversion}->[-1]->storage($mode)
+ if (@{$self->{diversion}} > 0);
+ my $old_mode = $self->{storage};
+ if (defined($mode)) {
+ die "invalid mode argument"
+ if ($mode !~ m/^(none|fold|all)$/);
+ $self->{storage} = $mode;
+ }
+ return $old_mode;
+}
+
# internal: split string into chunks
sub _chunking ($) {
my ($self, $string) = @_;
@@ -110,17 +125,19 @@
my $folderre = $self->{folderre};
while ($string =~ m/${folderre}()/s) {
my ($prolog, $id) = ($`, $1);
- push(@chunks, $prolog) if ($prolog ne '');
+ push(@chunks, $prolog) if ($prolog ne '' and $self->{storage} !~ m/^(none|fold)/);
die "empty folding object name"
if ($id eq '');
- my $object = $self->folding($id);
- $object = $self->new($id) if (not defined($object));
- die "cannot reuse or create folding sub object \"$id\""
- if (not defined($object));
- push(@chunks, $object);
+ if ($self->{storage} ne 'none') {
+ my $object = $self->folding($id);
+ $object = $self->new($id) if (not defined($object));
+ die "cannot reuse or create folding sub object \"$id\""
+ if (not defined($object));
+ push(@chunks, $object);
+ }
$string = $';
}
- push(@chunks, $string) if ($string ne '');
+ push(@chunks, $string) if ($string ne '' and $self->{storage} !~ m/^(none|fold)/);
return @chunks;
}
@@ -229,6 +246,7 @@
if (@{$self->{diversion}} > 0);
die "undefined folding object identifier"
if (not defined($id));
+ return undef if ($self->{storage} eq 'none');
if (ref($id)) {
die "folding object not of class String::Divert"
if ( UNIVERSAL::isa($id, "String::Divert")
@@ -318,6 +336,7 @@
}
else {
# create folder
+ return "" if ($self->{storage} eq 'none');
my $folder = sprintf($self->{foldermk}, $a);
return $folder;
}
@@ -337,6 +356,14 @@
sub undivert ($;$) {
my ($self, $num) = @_;
$num = 1 if (not defined($num));
+ if ($num !~ m|^\d+$|) {
+ my $name = $num;
+ for ($num = 1; $num <= @{$self->{diversion}}; $num++) {
+ last if ($self->{diversion}->[-$num]->{name} eq $name);
+ }
+ die "no object named \"$name\" found for undiversion"
+ if ($num > @{$self->{diversion}});
+ }
$num = @{$self->{diversion}} if ($num == 0);
die "less number (".scalar(@{$self->{diversion}}).") of diversions active than requested ($num) to undivert"
if ($num > @{$self->{diversion}});
|