I can't say I don't hope you're overruled, as I personally enjoy using that syntax all over the place and would be happy to submit patches to have the rest of QP act that way :) Nevertheless, here's another variant that retains the previous behavior, but with the more standard/one-line-shorter/arguably-clearer my (...) = @_ syntax. Of course there's always rcpt_config_minor as well

-Jared

Matt Sergeant wrote:
On Fri, 09 Jan 2009 22:00:36 -0600, Jared Johnson wrote:
Most notably for Address:host(), user(),
notes() and Connection::notes(), Transaction::notes(): it changes the
'set' version of these get/set methods to return $self.  This makes it
possible to do things like:

$rcpt->user('jaredj')->host('nmgi.com')->notes(score => 5.0);

where one was previously forced to do:

$rcpt->user('jaredj');
$rcpt->host('nmgi.com');
$rcpt->notes(score => 5.0);

Honestly I'd reject this part of the patch. It's contrary to what every other setter in qpsmtpd does, and makes for unintuitive code anyway.

Matt.

Index: lib/Qpsmtpd/Transaction.pm
===================================================================
--- lib/Qpsmtpd/Transaction.pm	(revision 967)
+++ lib/Qpsmtpd/Transaction.pm	(working copy)
@@ -55,11 +55,9 @@
 #}
 
 sub notes {
-  my $self = shift;
-  my $key  = shift;
-  @_ and $self->{_notes}->{$key} = shift;
-  #warn Data::Dumper->Dump([\$self->{_notes}], [qw(notes)]);
-  $self->{_notes}->{$key};
+  my ($self,$key,$value) = @_;
+  $self->{_notes}->{$key} = $value if defined $value;
+  return $self->{_notes}->{$key};
 }
 
 sub set_body_start {
Index: lib/Qpsmtpd/Address.pm
===================================================================
--- lib/Qpsmtpd/Address.pm	(revision 967)
+++ lib/Qpsmtpd/Address.pm	(working copy)
@@ -317,6 +317,20 @@
     return $self->{_host};
 }
 
+=head2 notes($key[,$value])
+
+Get or set a note on the recipient. This is a piece of data that you wish
+to attach to the recipient and read somewhere else. For example you can
+use this to pass data between plugins.
+
+=cut
+
+sub notes {
+  my ($self,$key,$value) = @_;
+  $self->{_notes}->{$key} = $value if defined $value;
+  return $self->{_notes}->{$key};
+}
+
 sub _addr_cmp {
     require UNIVERSAL;
     my ($left, $right, $swap) = @_;
Index: lib/Qpsmtpd/Connection.pm
===================================================================
--- lib/Qpsmtpd/Connection.pm	(revision 967)
+++ lib/Qpsmtpd/Connection.pm	(working copy)
@@ -108,10 +108,9 @@
 }
 
 sub notes {
-  my $self = shift;
-  my $key  = shift;
-  @_ and $self->{_notes}->{$key} = shift;
-  $self->{_notes}->{$key};
+  my ($self,$key,$value) = @_;
+  $self->{_notes}->{$key} = $value if defined $value;
+  return $self->{_notes}->{$key};
 }
 
 sub reset {
@@ -200,7 +199,9 @@
 
 =head2 notes($key [, $value])
 
-Connection-wide notes, used for passing data between plugins.
+Get or set a note on the transaction. This is a piece of data that you wish
+to attach to the transaction and read somewhere else. For example you can
+use this to pass data between plugins.
 
 =head2 clone([%args])
 

Reply via email to