| Mail-SPF documentation | Contained in the Mail-SPF distribution. |
Mail::SPF::Base - Base class for Mail::SPF classes
use base 'Mail::SPF::Base';
sub new {
my ($class, @options) = @_;
my $self = $class->SUPER::new(@options);
...
return $self;
}
Mail::SPF::Base is a common base class for all Mail::SPF classes.
The following constructor is provided:
Creates a new object of the class on which the constructor was invoked. The provided options are stored as key/value pairs in the new object.
The new constructor may also be called on an object, in which case the
object is cloned. Any options provided override those from the old object.
There are no common options defined in Mail::SPF::Base.
The following class methods are provided:
Returns the class name of the class or object on which it is invoked.
The following class methods are provided:
Creates an accessor method in the class on which it is invoked. The accessor has the given name and accesses the object field of the same name. If $readonly is true, the accessor is made read-only.
There are no common instance methods defined in Mail::SPF::Base.
For availability, support, and license information, see the README file included with Mail::SPF.
Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
| Mail-SPF documentation | Contained in the Mail-SPF distribution. |
# # Mail::SPF::Base # Base class for Mail::SPF classes. # # (C) 2005-2008 Julian Mehnle <julian@mehnle.net> # 2005 Shevek <cpan@anarres.org> # $Id: Base.pm 50 2008-08-17 21:28:15Z Julian Mehnle $ # ############################################################################## package Mail::SPF::Base;
use warnings; use strict; use Error ':try'; use Mail::SPF::Exception; use constant TRUE => (0 == 0); use constant FALSE => not TRUE;
sub new { my ($self, %options) = @_; my $new = ref($self) ? # Was new() invoked on a class or an object? { %$self, %options } # Object: clone source object, override fields. : \%options; # Class: create new object. return bless($new, $self->class); }
sub class { my ($self) = @_; return ref($self) || $self; }
sub make_accessor { my ($class, $name, $readonly) = @_; throw Mail::SPF::EClassMethod if ref($class); my $accessor_name = "${class}::${name}"; my $accessor; if ($readonly) { $accessor = sub { local *__ANON__ = $accessor_name; my ($self, @value) = @_; throw Mail::SPF::EInstanceMethod if not ref($self); throw Mail::SPF::EReadOnlyValue("$accessor_name is read-only") if @value; return $self->{$name}; }; } else { $accessor = sub { local *__ANON__ = $accessor_name; my ($self, @value) = @_; throw Mail::SPF::EInstanceMethod if not ref($self); $self->{$name} = $value[0] if @value; return $self->{$name}; }; } { no strict 'refs'; *{$accessor_name} = $accessor; } return $accessor; }
TRUE;