[Catalyst-commits] r7989 - in Catalyst-Runtime/5.80/trunk: .
lib/Catalyst
groditi at dev.catalyst.perl.org
groditi at dev.catalyst.perl.org
Mon Jun 23 22:20:47 BST 2008
Author: groditi
Date: 2008-06-23 22:20:47 +0100 (Mon, 23 Jun 2008)
New Revision: 7989
Modified:
Catalyst-Runtime/5.80/trunk/
Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm
Log:
r18425 at martha (orig r7903): groditi | 2008-06-09 14:46:29 -0400
broken classdata version
Property changes on: Catalyst-Runtime/5.80/trunk
___________________________________________________________________
Name: svk:merge
- 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7893
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
+ 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:7576
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.80/branches/moose:7903
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst:4483
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm 2008-06-23 21:20:41 UTC (rev 7988)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/ClassData.pm 2008-06-23 21:20:47 UTC (rev 7989)
@@ -4,26 +4,51 @@
use Scalar::Util 'blessed';
sub mk_classdata {
- my ($declaredclass, $attribute, $data) = @_;
+ my ($class, $attribute) = @_;
confess("mk_classdata() is a class method, not an object method")
- if ref $declaredclass;
+ if blessed $class;
- my $accessor = sub {
- my $wantclass = blessed($_[0]) || $_[0];
-
- return $wantclass->mk_classdata($attribute)->(@_)
- if @_>1 && $wantclass ne $declaredclass;
-
- $data = $_[1] if @_>1;
- return $data;
+ my $slot = '$'.$attribute;
+ my $accessor = sub {
+ if(@_ > 1){
+ $_[0]->meta->add_package_symbol($slot, \ $_[1]);
+ return $_[1];
+ }
+ foreach my $super ( $_[0], $_[0]->meta->linearized_isa ) {
+ my $meta = $super->meta;
+ if( $meta->has_package_symbol($slot) ){
+ return $meta->get_package_symbol($slot);
+ }
+ }
+ return;
};
+ my $accessor = eval $code;
+ confess("Failed to create accessor: $@ \n $code \n")
+ unless ref $accessor eq 'CODE';
+ my $meta = $class->meta;
my $alias = "_${attribute}_accessor";
- $declaredclass->meta->add_method($alias, $accessor);
- $declaredclass->meta->add_method($attribute, $accessor);
+ $meta->add_method($alias, $accessor);
+ $meta->add_method($attribute, $accessor);
+ $class->$attribute($_[2]) if(@_ > 2);
return $accessor;
}
1;
__END__
+
+# my $code = ' sub {
+# if(@_ > 1){
+# $_[0]->meta->add_package_symbol(\''.$slot.'\', \ $_[1]);
+# return $_[1];
+# }
+# foreach my $super ( $_[0], $_[0]->meta->linearized_isa ) {
+# my $meta = $super->meta;
+# if( $meta->has_package_symbol(\''.$slot.'\') ){
+# return $meta->get_package_symbol(\''.$slot.'\');
+# }
+# }
+# return;
+# }';
+# my $accessor = eval $code;
More information about the Catalyst-commits
mailing list