r2816 - in
/packages/libclass-data-accessor-perl/branches/upstream/current:
Changes MANIFEST.SKIP META.yml README lib/Class/Data/Accessor.pm
t/Accessor.t
eloy at users.alioth.debian.org
eloy at users.alioth.debian.org
Tue May 30 14:39:37 UTC 2006
Author: eloy
Date: Tue May 30 14:39:35 2006
New Revision: 2816
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=2816
Log:
Load /tmp/tmp.QENSR31618/libclass-data-accessor-perl-0.03 into
packages/libclass-data-accessor-perl/branches/upstream/current.
Modified:
packages/libclass-data-accessor-perl/branches/upstream/current/Changes
packages/libclass-data-accessor-perl/branches/upstream/current/MANIFEST.SKIP
packages/libclass-data-accessor-perl/branches/upstream/current/META.yml
packages/libclass-data-accessor-perl/branches/upstream/current/README
packages/libclass-data-accessor-perl/branches/upstream/current/lib/Class/Data/Accessor.pm
packages/libclass-data-accessor-perl/branches/upstream/current/t/Accessor.t
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/Changes?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/Changes (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/Changes Tue May 30 14:39:35 2006
@@ -1,4 +1,9 @@
Revision history for Class::Data::Accessor.
+
+0.03 2006-06-23 19:50:23
+ - Added warning when attempting to make DESTROY accessor
+ - Added mk_classaccessors class method
+ - Doc patch (Aran Deltac)
0.02
- Doc fixes
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/MANIFEST.SKIP?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/MANIFEST.SKIP (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/MANIFEST.SKIP Tue May 30 14:39:35 2006
@@ -27,6 +27,7 @@
\.bak$
\.swp$
\.tdy$
+\.tmp$
\#$
\b\.#
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/META.yml?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/META.yml (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/META.yml Tue May 30 14:39:35 2006
@@ -1,6 +1,6 @@
---
name: Class-Data-Accessor
-version: 0.02
+version: 0.03
author: ~
abstract: 'Inheritable, overridable class and instance data accessor creation'
license: perl
@@ -9,5 +9,5 @@
provides:
Class::Data::Accessor:
file: lib/Class/Data/Accessor.pm
- version: 0.02
+ version: 0.03
generated_by: Module::Build version 0.26
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/README?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/README (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/README Tue May 30 14:39:35 2006
@@ -91,7 +91,10 @@
If you don't want this behaviour use Class::Data::Inheritable instead.
-Methods
+ "mk_classaccessor" will die if used as an object method instead of as a
+ class method.
+
+METHODS
mk_classaccessor
Class->mk_classaccessor($data_accessor_name);
Class->mk_classaccessor($data_accessor_name => $value);
@@ -113,6 +116,16 @@
$self->_Suitcase_accessor(@_);
}
+
+ Overriding accessors does not work in the same class as you declare the
+ accessor in. It only works in subclasses due to the fact that
+ subroutines are loaded at compile time and accessors are loaded at
+ runtime, thus overriding any subroutines with the same name in the same
+ class.
+
+ mk_classaccessors(@accessornames)
+ Takes a list of names and generates an accessor for each name in the
+ list using "mk_classaccessor".
AUTHORS
Based on the creative stylings of Damian Conway, Michael G Schwern, Tony
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/lib/Class/Data/Accessor.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/lib/Class/Data/Accessor.pm?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/lib/Class/Data/Accessor.pm (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/lib/Class/Data/Accessor.pm Tue May 30 14:39:35 2006
@@ -1,14 +1,18 @@
package Class::Data::Accessor;
use strict qw(vars subs);
+use Carp;
use vars qw($VERSION);
-$VERSION = '0.02';
+$VERSION = '0.03';
sub mk_classaccessor {
my ($declaredclass, $attribute, $data) = @_;
if( ref $declaredclass ) {
- require Carp;
- Carp::croak("mk_classaccessor() is a class method, not an object method");
+ croak("mk_classaccessor() is a class method, not an object method");
+ }
+
+ if( $attribute eq 'DESTROY' ) {
+ carp("Having a data accessor named DESTROY in '$declaredclass' is unwise.");
}
my $accessor = sub {
@@ -32,6 +36,14 @@
*{$declaredclass.'::'.$alias} = $accessor;
}
+sub mk_classaccessors {
+ my ($declaredclass, @attributes) = @_;
+
+ foreach my $attribute (@attributes) {
+ $declaredclass->mk_classaccessor($attribute);
+ }
+};
+
__END__
=head1 NAME
@@ -130,7 +142,10 @@
If you don't want this behaviour use L<Class::Data::Inheritable> instead.
-=head1 Methods
+C<mk_classaccessor> will die if used as an object method instead of as a
+class method.
+
+=head1 METHODS
=head2 mk_classaccessor
@@ -155,6 +170,17 @@
$self->_Suitcase_accessor(@_);
}
+Overriding accessors does not work in the same class as you declare
+the accessor in. It only works in subclasses due to the fact that
+subroutines are loaded at compile time and accessors are loaded at
+runtime, thus overriding any subroutines with the same name in the
+same class.
+
+=head2 mk_classaccessors(@accessornames)
+
+Takes a list of names and generates an accessor for each name in the list using
+C<mk_classaccessor>.
+
=head1 AUTHORS
Based on the creative stylings of Damian Conway, Michael G Schwern,
Modified: packages/libclass-data-accessor-perl/branches/upstream/current/t/Accessor.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libclass-data-accessor-perl/branches/upstream/current/t/Accessor.t?rev=2816&op=diff
==============================================================================
--- packages/libclass-data-accessor-perl/branches/upstream/current/t/Accessor.t (original)
+++ packages/libclass-data-accessor-perl/branches/upstream/current/t/Accessor.t Tue May 30 14:39:35 2006
@@ -1,5 +1,5 @@
use strict;
-use Test::More tests => 17;
+use Test::More tests => 19;
package Ray;
use base qw(Class::Data::Accessor);
@@ -49,3 +49,28 @@
"And they can set their own copy";
is +Gun->DataFile, "/tmp/stuff", "But it doesn't touch the value on the class";
+
+
+{
+ my $warned = 0;
+
+ local $SIG{__WARN__} = sub {
+ if (shift =~ /DESTROY/i) {
+ $warned++;
+ };
+ };
+
+ Ray->mk_classaccessor('DESTROY');
+
+ ok($warned, 'Warn when creating DESTROY');
+
+ # restore non-accessorized DESTROY
+ no warnings;
+ *Ray::DESTROY = sub {};
+};
+
+eval {
+ $obj->mk_classaccessor('foo');
+};
+like($@, qr{not an object method}, 'Die when used as an object method');
+
More information about the Pkg-perl-cvs-commits
mailing list