[Catalyst-commits] r7906 - in Catalyst-Runtime/5.80/branches/moose:
lib lib/Catalyst t
groditi at dev.catalyst.perl.org
groditi at dev.catalyst.perl.org
Mon Jun 9 23:37:44 BST 2008
Author: groditi
Date: 2008-06-09 23:37:44 +0100 (Mon, 09 Jun 2008)
New Revision: 7906
Modified:
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/AttrContainer.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/ClassData.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Component.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Model.pm
Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/View.pm
Catalyst-Runtime/5.80/branches/moose/t/unit_core_classdata.t
Log:
config wins, groditi loses. FUCK YOU FOR SUPPORTING THAT STUPID BEHAVIOR
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/AttrContainer.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/AttrContainer.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/AttrContainer.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -2,15 +2,13 @@
use Moose;
use Catalyst::Exception;
-
-with 'Catalyst::ClassData';
use Scalar::Util 'blessed';
+with 'Catalyst::ClassData';
no Moose;
-__PACKAGE__->mk_classdata($_) for qw/_attr_cache _action_cache/;
-__PACKAGE__->_attr_cache( {} );
-__PACKAGE__->_action_cache( [] );
+__PACKAGE__->mk_classdata(_attr_cache => {} );
+__PACKAGE__->mk_classdata( _action_cache => [] );
# note - see attributes(3pm)
sub MODIFY_CODE_ATTRIBUTES {
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/ClassData.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/ClassData.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/ClassData.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -11,15 +11,20 @@
my $slot = '$'.$attribute;
my $accessor = sub {
+ my $meta = $_[0]->meta;
if(@_ > 1){
- $_[0]->meta->add_package_symbol($slot, \ $_[1]);
+ $meta->add_package_symbol($slot, \ $_[1]);
return $_[1];
}
- foreach my $super ( (blessed $_[0] || $_[0]), $_[0]->meta->linearized_isa ) {
- my $meta = Moose::Meta::Class->initialize($super);
- if( $meta->has_package_symbol($slot) ){
- return ${ $meta->get_package_symbol($slot) };
+ if( $meta->has_package_symbol($slot) ){
+ return ${ $meta->get_package_symbol($slot) };
+ } else {
+ foreach my $super ( $meta->linearized_isa ) {
+ my $super_meta = Moose::Meta::Class->initialize($super);
+ if( $super_meta->has_package_symbol($slot) ){
+ return ${ $super_meta->get_package_symbol($slot) };
+ }
}
}
return;
@@ -39,3 +44,26 @@
1;
__END__
+
+
+=head1 NAME
+
+Catalyst::ClassData - Class data acessors
+
+=head1 METHODS
+
+=head2 mk_classdata $name, $optional_value
+
+A moose-safe clone of L<Class::Data::Inheritable> that borrows some ideas from
+L<Class::Accessor::Grouped>;
+
+=head1 AUTHOR
+
+Guillermo Roditi
+
+=head1 COPYRIGHT
+
+This program is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Component.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Component.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Component.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -54,7 +54,7 @@
=cut
-__PACKAGE__->mk_classdata($_) for qw/_config _plugins/;
+__PACKAGE__->mk_classdata('_plugins');
around new => sub {
my ( $orig, $self) = @_;
@@ -83,15 +83,39 @@
}
sub config {
- my $self = shift;
- my $config = $self->_config ||{};
- if (@_) {
- my $newconfig = { %{@_ > 1 ? {@_} : $_[0]} };
- $self->_config(
- $self->merge_config_hashes( $config, $newconfig )
- );
+ my $self = shift;
+ my $class = blessed $self || $self;
+
+ my $config;
+ my $meta = $class->meta;
+ if( $meta->has_package_symbol('$config') ){
+ $config = ${ $meta->get_package_symbol('$config') };
+ } else {
+ foreach my $super ( $meta->linearized_isa ) {
+ my $super_meta = Moose::Meta::Class->initialize($super);
+ if( $super_meta->has_package_symbol('$config') ){
+ $config = ${ $super_meta->get_package_symbol('$config') };
+ unless( @_ ){ #don't copy and write it twice
+ $config = $class->merge_config_hashes( $config, {} );
+ $meta->add_package_symbol('$config', \ $config);
+ }
+ last;
+ }
}
- return $config;
+ }
+
+ unless( defined $config ){
+ $config = {};
+ $meta->add_package_symbol('$config', \ $config) unless @_;
+ }
+
+ if (@_) {
+ my $from_args = { %{@_ > 1 ? {@_} : $_[0]} };
+ my $new_config = $class->merge_config_hashes( $config, $from_args);
+ $meta->add_package_symbol('$config', \ $new_config);
+ }
+
+ return $config;
}
sub merge_config_hashes {
@@ -106,6 +130,8 @@
. " did not override Catalyst::Component::process" );
}
+
+__PACKAGE__->meta->make_immutable;
1;
__END__
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Controller.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -361,6 +361,8 @@
no Moose;
+__PACKAGE__->meta->make_immutable;
+
1;
__END__
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Model.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Model.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/Model.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -36,4 +36,6 @@
=cut
+__PACKAGE__->meta->make_immutable;
+
1;
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/View.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/View.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst/View.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -65,6 +65,6 @@
=cut
no Moose;
-#__PACKAGE__->meta->make_immutable();
+__PACKAGE__->meta->make_immutable();
1;
Modified: Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/lib/Catalyst.pm 2008-06-09 22:37:44 UTC (rev 7906)
@@ -2449,4 +2449,6 @@
no Moose;
+__PACKAGE__->meta->make_immutable;
+
1;
Modified: Catalyst-Runtime/5.80/branches/moose/t/unit_core_classdata.t
===================================================================
--- Catalyst-Runtime/5.80/branches/moose/t/unit_core_classdata.t 2008-06-09 20:42:44 UTC (rev 7905)
+++ Catalyst-Runtime/5.80/branches/moose/t/unit_core_classdata.t 2008-06-09 22:37:44 UTC (rev 7906)
@@ -3,7 +3,7 @@
use strict;
use warnings;
use Scalar::Util qw/refaddr blessed/;
-use Test::More tests => 32;
+use Test::More tests => 37;
{
package ClassDataTest;
@@ -28,7 +28,13 @@
my $scalarref2 = \$scalar2;
my $coderef2 = sub { "beep" };
+ my $scalar3 = '300';
+ my $arrayref3 = [];
+ my $hashref3 = {};
+ my $scalarref3 = \$scalar3;
+ my $coderef3 = sub { "beep" };
+
my @accessors = qw/_arrayref _hashref _scalarref _coderef _scalar/;
ClassDataTest->mk_classdata($_) for @accessors;
can_ok('ClassDataTest', @accessors);
@@ -82,3 +88,15 @@
is(refaddr(ClassDataTest->_scalarref), refaddr($scalarref));
is(refaddr(ClassDataTest->_coderef), refaddr($coderef));
is(ClassDataTest->_scalar, $scalar);
+
+ClassDataTest->_arrayref($arrayref3);
+ClassDataTest->_hashref($hashref3);
+ClassDataTest->_scalarref($scalarref3);
+ClassDataTest->_coderef($coderef3);
+ClassDataTest->_scalar($scalar3);
+
+is(refaddr(ClassDataTest->_arrayref), refaddr($arrayref3));
+is(refaddr(ClassDataTest->_hashref), refaddr($hashref3));
+is(refaddr(ClassDataTest->_scalarref), refaddr($scalarref3));
+is(refaddr(ClassDataTest->_coderef), refaddr($coderef3));
+is(ClassDataTest->_scalar, $scalar3);
More information about the Catalyst-commits
mailing list