[swiftsieve] [PATCH] Change implict stringification of Condition/Rule/Script to write().
Vsevolod Kozlov
zaba at thorium.homeunix.org
Wed Feb 18 17:29:46 UTC 2009
---
lib/App/Swiftsieve/Sieve.pm | 4 +---
lib/App/Swiftsieve/Sieve/Condition.pm | 4 +---
lib/App/Swiftsieve/Sieve/Rule.pm | 4 +---
lib/App/Swiftsieve/Sieve/Script.pm | 7 +++----
t/sieve-condition.t | 2 +-
t/sieve-rule.t | 4 ++--
t/sieve-script.t | 11 ++++++++---
7 files changed, 17 insertions(+), 19 deletions(-)
diff --git a/lib/App/Swiftsieve/Sieve.pm b/lib/App/Swiftsieve/Sieve.pm
index ffc2b5c..d6d2a55 100644
--- a/lib/App/Swiftsieve/Sieve.pm
+++ b/lib/App/Swiftsieve/Sieve.pm
@@ -68,13 +68,11 @@ sub get {
Writes the given script to the server
-(App::Swiftsieve::Sieve::Script stringifies to a Sieve script text.)
-
=cut
sub put {
my($self, $script_name, $script) = @_;
$SIG{__WARN__} = sub { die(@_); };
- $self->{conn}->put($script_name, "$script");
+ $self->{conn}->put($script_name, $script->write);
$SIG{__WARN__} = undef;
}
diff --git a/lib/App/Swiftsieve/Sieve/Condition.pm b/lib/App/Swiftsieve/Sieve/Condition.pm
index 5389332..182cbbb 100644
--- a/lib/App/Swiftsieve/Sieve/Condition.pm
+++ b/lib/App/Swiftsieve/Sieve/Condition.pm
@@ -19,8 +19,6 @@ use strict;
use warnings;
use base qw(Class::Accessor::Fast);
-use overload
- '""' => \&write;
use App::Swiftsieve::Util qw(allowed_value sieve_escape sieve_unescape);
@@ -36,7 +34,7 @@ Conditions are part of Sieve's rules. Swiftsieve simplifies a condition to havin
a haystack, a needle and an operator.
To get the text representation of this condition, ready for the Sieve server, you
-can just stringify it, thanks to overloading.
+should call the write() method.
=head1 DESCRIPTION
diff --git a/lib/App/Swiftsieve/Sieve/Rule.pm b/lib/App/Swiftsieve/Sieve/Rule.pm
index 67235c1..64bb677 100644
--- a/lib/App/Swiftsieve/Sieve/Rule.pm
+++ b/lib/App/Swiftsieve/Sieve/Rule.pm
@@ -18,8 +18,6 @@ package App::Swiftsieve::Sieve::Rule;
use strict;
use warnings;
-use overload '""' => \&write;
-
use base qw(Class::Accessor::Fast);
use App::Swiftsieve::Sieve::Condition;
use App::Swiftsieve::Util qw(allowed_value sieve_escape sieve_unescape);
@@ -37,7 +35,7 @@ Rules are the workhorse of Sieve scripts. Swiftsieve limits rules to having
multiple conditions, joined by allof or anyof, and a single action.
To get the text representation of this rule, ready for the Sieve server, you
-can just stringify it, thanks to overloading.
+should call the write() method.
=head1 DESCRIPTION
diff --git a/lib/App/Swiftsieve/Sieve/Script.pm b/lib/App/Swiftsieve/Sieve/Script.pm
index 022dfde..1b6c495 100644
--- a/lib/App/Swiftsieve/Sieve/Script.pm
+++ b/lib/App/Swiftsieve/Sieve/Script.pm
@@ -18,8 +18,6 @@ package App::Swiftsieve::Sieve::Script;
use strict;
use warnings;
-use overload '""' => \&write;
-
use App::Swiftsieve::Sieve::Rule;
use App::Swiftsieve::Sieve::Condition;
@@ -33,7 +31,7 @@ The Script class parses and writes the highest level of Sieve handling, the
script.
To get the text representation of this script, ready for the Sieve server, you
-can just stringify it, thanks to overloading.
+should call the write() method.
=head1 DESCRIPTION
@@ -122,7 +120,8 @@ Returns the Sieve representation of this script
sub write {
my($self) = @_;
my $require = 'require ["fileinto", "reject", "regex"];';
- return "$require\n" . join("\nels", $self->rules) . "\n";
+ my @written_rules = map { $_->write } $self->rules;
+ return "$require\n" . join("\nels", @written_rules) . "\n";
}
=item B<rules>
diff --git a/t/sieve-condition.t b/t/sieve-condition.t
index f385bcf..046b2af 100644
--- a/t/sieve-condition.t
+++ b/t/sieve-condition.t
@@ -32,4 +32,4 @@ is($rule->write,
$rule->haystack('size');
$rule->operator('over');
$rule->needle('2342');
-is("$rule", 'size :over 2342', 'size over');
+is($rule->write, 'size :over 2342', 'size over');
diff --git a/t/sieve-rule.t b/t/sieve-rule.t
index 6d12a37..25694f3 100644
--- a/t/sieve-rule.t
+++ b/t/sieve-rule.t
@@ -67,7 +67,7 @@ if allof (
fileinto "foo";
}
END
-eq_or_diff("$new_rule", $should_be, 'rule written correctly');
+eq_or_diff($new_rule->write, $should_be, 'rule written correctly');
my $disabled_source = <<END;
if false { # SWIFTSIEVE_DISABLED_RULE
@@ -103,4 +103,4 @@ if allof (
}
}
END
-eq_or_diff("$new_disabled_rule", $disabled_should_be, 'disabled rule written correctly');
+eq_or_diff($new_disabled_rule->write, $disabled_should_be, 'disabled rule written correctly');
diff --git a/t/sieve-script.t b/t/sieve-script.t
index 7513d72..7881272 100644
--- a/t/sieve-script.t
+++ b/t/sieve-script.t
@@ -17,6 +17,7 @@ use strict;
use warnings;
use Test::More tests => 15;
+use Test::MockObject;
require_ok('App::Swiftsieve::Sieve::Script');
@@ -42,14 +43,18 @@ is($rules[1]->condition_join, 'allof', 'second rule, condition join');
is($rules[1]->action_command, 'fileinto', 'second rule, action command');
my $new_script = new App::Swiftsieve::Sieve::Script;
-$new_script->add_rule("if true { keep; }");
-$new_script->add_rule("if true { keep; }");
+my $mock_rule_1 = new Test::MockObject;
+$mock_rule_1->mock ('write', sub { return "if true { keep; }" });
+$new_script->add_rule($mock_rule_1);
+my $mock_rule_2 = new Test::MockObject;
+$mock_rule_2->mock ('write', sub { return "if true { keep; }" });
+$new_script->add_rule($mock_rule_2);
my $should_be = <<END;
require ["fileinto", "reject", "regex"];
if true { keep; }
elsif true { keep; }
END
-is("$new_script", $should_be, 'script written correctly');
+is($new_script->write, $should_be, 'script written correctly');
my $disabled_source = <<END;
require ["fileinto"];
--
1.6.0.6
More information about the Swiftsieve-devel
mailing list