----------------------------------------------------------------------
r31152: schwern | 2007-06-12 19:43:58 -0700
lvalue subroutines are experimental and don't seem to work right in the
debugger. Get rid of them.
----------------------------------------------------------------------
=== local/Class-Trait/t/050_Trait_Config_test.t
==================================================================
--- local/Class-Trait/t/050_Trait_Config_test.t (revision 31151)
+++ local/Class-Trait/t/050_Trait_Config_test.t (revision 31152)
@@ -55,12 +55,12 @@
# add in those same variables
-$trait_config->name = $name;
-$trait_config->sub_traits = $sub_traits;
-$trait_config->requirements = $requirements;
-$trait_config->methods = $methods;
-$trait_config->overloads = $overloads;
-$trait_config->conflicts = $conflicts;
+$trait_config->name($name);
+$trait_config->sub_traits($sub_traits);
+$trait_config->requirements($requirements);
+$trait_config->methods($methods);
+$trait_config->overloads($overloads);
+$trait_config->conflicts($conflicts);
# now test that they were successfully inserted
=== local/Class-Trait/lib/Class/Trait/Config.pm
==================================================================
--- local/Class-Trait/lib/Class/Trait/Config.pm (revision 31151)
+++ local/Class-Trait/lib/Class/Trait/Config.pm (revision 31152)
@@ -3,8 +3,10 @@
use strict;
use warnings;
-our $VERSION = '0.04';
+use base qw(Class::Accessor::Fast);
+our $VERSION = '0.04_01';
+
# we are going for a very struct-like class here to try and keep the
# syntactical noise down.
@@ -23,31 +25,10 @@
}, $class;
}
-# just use basic l-valued methods for clarity and speed.
-sub name : lvalue {
- $_[0]->{name};
-}
+__PACKAGE__->mk_accessors(qw(
+ name sub_traits requirements methods overloads conflicts
+));
-sub sub_traits : lvalue {
- $_[0]->{sub_traits};
-}
-
-sub requirements : lvalue {
- $_[0]->{requirements};
-}
-
-sub methods : lvalue {
- $_[0]->{methods};
-}
-
-sub overloads : lvalue {
- $_[0]->{overloads};
-}
-
-sub conflicts : lvalue {
- $_[0]->{conflicts};
-}
-
# a basic clone function for moving in and out of the cache.
sub clone {
my $self = shift;
@@ -95,34 +76,31 @@
=item B<name>
-An C<lvalue> subroutine for accessing the C<name> string field of the
-Class::Trait::Config object.
+An accessor to the C<name> string field of the Class::Trait::Config object.
=item B<sub_traits>
-An C<lvalue> subroutine for accessing the C<sub_traits> array reference field
-of the Class::Trait::Config object.
+An accessor to the C<sub_traits> array reference field of the Class::Trait::Config object.
=item B<requirements>
-An C<lvalue> subroutine for accessing the C<requirements> hash reference field
+An accessor to the C<requirements> hash reference field
of the Class::Trait::Config object. Note, the requirements field is a hash
reference to speed requirement lookup, the values of the hash are simply
booleans.
=item B<methods>
-An C<lvalue> subroutine for accessing the C<methods> hash reference field of
-the Class::Trait::Config object.
+An accessor to the C<methods> hash reference field of the Class::Trait::Config object.
=item B<overloads>
-An C<lvalue> subroutine for accessing the C<overloads> hash reference field of
+An accessor to the C<overloads> hash reference field of
the Class::Trait::Config object.
=item B<conflicts>
-An C<lvalue> subroutine for accessing the C<conflicts> hash reference field of
+An accessor to the C<conflicts> hash reference field of
the Class::Trait::Config object. Note, the conflicts field is a hash reference
to speed conflict lookup, the values of the hash are simply booleans.
=== local/Class-Trait/lib/Class/Trait.pm
==================================================================
--- local/Class-Trait/lib/Class/Trait.pm (revision 31151)
+++ local/Class-Trait/lib/Class/Trait.pm (revision 31152)
@@ -684,7 +684,7 @@
# initialize our trait configuration
my $trait_config = Class::Trait::Config->new();
- $trait_config->name = $trait;
+ $trait_config->name($trait);
_get_trait_requirements($trait_config);
_get_trait_methods($trait_config);
@@ -704,7 +704,7 @@
if (DEBUG) {
$debug_indent--;
debug "< dumping trait ($trait) with subtraits ("
- . ( join ", " => @{ $trait_config->{sub_traits} } ) . ") : "
+ . ( join ", " => @{ $trait_config->sub_traits } ) . ") : "
. Data::Dumper::Dumper($trait_config);
}
}
@@ -737,8 +737,8 @@
# create a new trait config to represent the combined traits
my $trait_config = Class::Trait::Config->new();
- $trait_config->name = $overriding_trait->name;
- $trait_config->sub_traits = [
+ $trait_config->name($overriding_trait->name);
+ $trait_config->sub_traits([
# if we have a composite trait we dont want to include the name here
# as it is actually defined better in the sub_traits field, but if we
@@ -746,19 +746,22 @@
( ( COMPOSITE() eq $trait->name ) ? () : $trait->name ),
@{ $trait->sub_traits }
- ];
+ ]);
# let the overriding trait override the methods in the regular trait
- $trait_config->methods
- = { %{ $trait->methods }, %{ $overriding_trait->methods } };
+ $trait_config->methods(
+ { %{ $trait->methods }, %{ $overriding_trait->methods } }
+ );
# the same for overloads
- $trait_config->overloads
- = { %{ $trait->overloads }, %{ $overriding_trait->overloads } };
+ $trait_config->overloads(
+ { %{ $trait->overloads }, %{ $overriding_trait->overloads } }
+ );
# now combine the requirements as well
- $trait_config->requirements
- = { %{ $trait->requirements }, %{ $overriding_trait->requirements } };
+ $trait_config->requirements(
+ { %{ $trait->requirements }, %{ $overriding_trait->requirements } }
+ );
if (DEBUG) {
debug "? checking for requirement fufillment";
@@ -838,7 +841,7 @@
# get any requirements in the trait and turn it into a hash so we can
# track stuff easier
- $trait_config->requirements = { map { $_ => 1 } @{"${trait}::REQUIRES"} }
+ $trait_config->requirements({ map { $_ => 1 } @{"${trait}::REQUIRES"} })
if defined @{"${trait}::"}{REQUIRES};
}
@@ -867,7 +870,7 @@
}
$implementation_for{$_} = $method;
}
- $trait_config->methods = \%implementation_for;
+ $trait_config->methods(\%implementation_for);
}
sub _get_trait_overloads {
@@ -884,7 +887,7 @@
debug "< getting overloads for ${trait}" if DEBUG;
# get the overload parameter hash
- $trait_config->overloads = { %{"${trait}::OVERLOADS"} }
+ $trait_config->overloads({ %{"${trait}::OVERLOADS"} })
if defined %{"${trait}::OVERLOADS"};
}
@@ -1012,7 +1015,7 @@
my $trait_config = Class::Trait::Config->new();
# we are making a composite trait, so lets call it as such
- $trait_config->name = COMPOSITE;
+ $trait_config->name(COMPOSITE);
$debug_indent++ if DEBUG;
=== local/Class-Trait/Build.PL
==================================================================
--- local/Class-Trait/Build.PL (revision 31151)
+++ local/Class-Trait/Build.PL (revision 31152)
@@ -8,9 +8,10 @@
dist_author => 'Curtis "Ovid" Poe <ovid@cpan.org>',
dist_version_from => 'lib/Class/Trait.pm',
requires => {
- 'Test::Differences' => 0.47,
- 'Test::Simple' => 0.62,
- 'File::Spec' => 0,
+ 'Test::Differences' => 0.47,
+ 'Test::Simple' => 0.62,
+ 'File::Spec' => 0,
+ 'Class::Accessor::Fast' => 0,
},
add_to_cleanup => ['Class-Trait-*'],
create_makefile_pl => 'traditional',