Skip Menu |

This queue is for tickets about the UML-Class-Simple CPAN distribution.

Report information
The Basics
Id: 40304
Status: resolved
Priority: 0/
Queue: UML-Class-Simple

People
Owner: Nobody in particular
Requestors: djh [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.16
Fixed in: (no value)



Subject: handle Class::Accessor::Grouped properties
I'm trying to produce diagrams of some modules that make use of Class::Accessor::Grouped and was losing properties. The following change seems to allow UCS to generate them. I don't understand the whys and wherefores of the second edit but it appears to be necessary. --- UML/Class/Simple-0-16.pm 2008-09-13 10:35:49.000000000 +0100 +++ UML/Class/Simple.pm 2008-10-23 14:27:09.000000000 +0100 @@ -339,7 +339,7 @@ name => $pkg, methods => [], properties => [], subclasses => [], }; - my $from_class_accessor = $pkg->isa('Class::Accessor') || $pkg->isa('Class::Accessor::Fast'); + my $from_class_accessor = $pkg->isa('Class::Accessor') || $pkg->isa('Class::Accessor::Fast') || $pkg->isa('Class::Accessor::Grouped'); #accessor_name_for # If you want to gather only the functions defined in @@ -385,7 +385,7 @@ if (! $self->{inherited_methods}) { my $source_name = Devel::Peek::CvGV($method->[3]); $source_name =~ s/^\*//; - next if $method->[0] ne $source_name; + next if $method->[0] ne $source_name and $source_name !~ /^Class::Accessor::Grouped::__ANON__/; } $method = $method->[2]; next if $public_only && $method =~ /^_/o;
Subject: Re: [rt.cpan.org #40304] handle Class::Accessor::Grouped properties
Date: Fri, 24 Oct 2008 10:05:29 +0800
To: bug-UML-Class-Simple [...] rt.cpan.org
From: agentzh <agentzh [...] gmail.com>
On Thu, Oct 23, 2008 at 9:36 PM, Dave Howorth via RT <bug-UML-Class-Simple@rt.cpan.org> wrote: Show quoted text
> > > I'm trying to produce diagrams of some modules that make use of > Class::Accessor::Grouped and was losing properties. The following change > seems to allow UCS to generate them. I don't understand the whys and > wherefores of the second edit but it appears to be necessary. >
I'll try to include this patch in the next release. I really appreciate it :) It'd be great if you can further provide some minimized test cases for this or I'll have to code up some myself ;) Thanks! -agentzh
Subject: Re: [rt.cpan.org #40304] handle Class::Accessor::Grouped properties
Date: Mon, 27 Oct 2008 17:16:04 +0800
To: bug-UML-Class-Simple [...] rt.cpan.org
From: agentzh <agentzh [...] gmail.com>
On Fri, Oct 24, 2008 at 10:05 AM, agentzh <agentzh@gmail.com> wrote: Show quoted text
> > I'll try to include this patch in the next release. I really appreciate it :) >
Done. Already included in the 0.17 release (which should appear on the CPAN mirror near you in the next few hours). Show quoted text
> It'd be great if you can further provide some minimized test cases for > this or I'll have to code up some myself ;) >
I've coded up a small test case myself: http://svn.berlios.de/svnroot/repos/umlclass/t/class-accessor-grouped.t http://svn.berlios.de/svnroot/repos/umlclass/t/data/TestClassAccessorGrouped.pm Please do some sanity-check. Thanks! -agentzh
feel free to reopen this ticket if you have further issues.
On Mon Oct 27 05:24:42 2008, AGENT wrote: Show quoted text
> feel free to reopen this ticket if you have further issues.
Murphy struck :( Shortly after I posted the patch I realized it didn't quite work (there are some inherited properties shown in subclasses when they're not wanted). I did a quick fix for that but other things interrupted and I haven't had time to test it properly. I'll get back with a modified patch once I have the tuits to run some more tests.
OK, here's a second attempt, with some tests. --- Simple-0.17.pm 2008-11-05 11:02:44.000000000 +0000 +++ Simple-0.17+.pm 2008-11-05 16:43:28.000000000 +0000 @@ -4,7 +4,7 @@ use warnings; no warnings 'redefine'; -our $VERSION = '0.17'; +our $VERSION = '0.17+djh'; #use Smart::Comments; use Carp qw(carp confess); @@ -351,7 +351,8 @@ my $methods = Class::Inspector->methods($pkg, 'expanded'); if ($methods and ref($methods) eq 'ARRAY') { if ($from_class_accessor) { - my %functions = map { $_->[2] => 1 } @$methods; # create hash from array + my $i = 0; + my %functions = map { $_->[2] => $i++ } @$methods; # create hash from array ### %functions #my @accessors = map { /^_(.*)_accessor$/; $1 } keys %functions; ### @accessors @@ -362,9 +363,12 @@ if ($meth =~ /^_(.*)_accessor$/) { my $accessor = $1; if (exists $functions{$accessor}) { + if ($self->{inherited_methods} + or $methods->[$functions{$accessor}]->[1] eq $pkg) { + push @{ $classes[-1]->{properties} }, $accessor; + } delete $functions{$accessor}; delete $functions{"_${accessor}_accessor"}; - push @{ $classes[-1]->{properties} }, $accessor; } next; } @@ -373,7 +377,10 @@ my $accessor = $1; delete $functions{$meth}; if (!$accessors{$accessor}) { - push @{ $classes[-1]->{properties} }, $accessor; + if ($self->{inherited_methods} + or $methods->[$functions{$accessor}]->[1] eq $pkg) { + push @{ $classes[-1]->{properties} }, $accessor; + } $accessors{$accessor} = 1; } } @@ -388,8 +395,7 @@ if (! $self->{inherited_methods}) { my $source_name = Devel::Peek::CvGV($method->[3]); $source_name =~ s/^\*//; - next if $method->[0] ne $source_name and - $source_name !~ /^Class::Accessor::Grouped::__ANON__/; + next if $method->[0] ne $source_name; } $method = $method->[2]; next if $public_only && $method =~ /^_/o; and two updated files for the test plus an extra test class: --- t/class-accessor-grouped.t 2008-10-27 07:32:05.000000000 +0000 +++ t/class-accessor-grouped.t 2008-11-05 11:00:56.000000000 +0000 @@ -14,7 +14,7 @@ $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys=1; -plan tests => 1; +plan tests => 3; require "t/data/TestClassAccessorGrouped.pm"; my $painter = UML::Class::Simple->new(['TestClassAccessorGrouped']); @@ -26,7 +26,8 @@ 'classes' => [ { 'methods' => [ - 'blah' + 'blah', + 'overridden' ], 'name' => 'TestClassAccessorGrouped', 'properties' => [ @@ -43,3 +44,68 @@ }; _EOC_ + +require "t/data/TestClassAccessorGroupedInheritance.pm"; +my $painter2 = UML::Class::Simple->new(['TestClassAccessorGroupedInheritance']); + +my $dom2 = $painter2->as_dom; + +is Dumper($dom2), <<'_EOC_'; +$VAR1 = { + 'classes' => [ + { + 'methods' => [ + 'overridden', + 'subclass_only' + ], + 'name' => 'TestClassAccessorGroupedInheritance', + 'properties' => [ + 'lr1name', + 'lr2name', + 'multiple1', + 'multiple2', + 'result_class', + 'singlefield', + 'sub_lr1name', + 'sub_lr2name', + 'sub_multiple1', + 'sub_multiple2', + 'sub_result_class', + 'sub_singlefield' + ], + 'subclasses' => [] + } + ] +}; +_EOC_ + + +my $painter3 = UML::Class::Simple->new(['TestClassAccessorGroupedInheritance']); + +$painter3->inherited_methods(0); + +my $dom3 = $painter3->as_dom; + +is Dumper($dom3), <<'_EOC_'; +$VAR1 = { + 'classes' => [ + { + 'methods' => [ + 'overridden', + 'subclass_only' + ], + 'name' => 'TestClassAccessorGroupedInheritance', + 'properties' => [ + 'sub_lr1name', + 'sub_lr2name', + 'sub_multiple1', + 'sub_multiple2', + 'sub_result_class', + 'sub_singlefield' + ], + 'subclasses' => [] + } + ] +}; +_EOC_ + --- t/data/TestClassAccessorGrouped.pm 2008-10-27 07:23:33.000000000 +0000 +++ t/data/TestClassAccessorGrouped.pm 2008-11-04 16:46:07.000000000 +0000 @@ -7,6 +7,9 @@ __PACKAGE__->mk_group_accessors('listref', [qw/lr1name lr1field/], [qw/lr2name lr2field/]); __PACKAGE__->mk_group_accessors('component_class', 'result_class'); +sub overridden { +} + sub blah { } cat t/data/TestClassAccessorGroupedInheritance.pm package TestClassAccessorGroupedInheritance; use base 'TestClassAccessorGrouped'; __PACKAGE__->mk_group_accessors('single', 'sub_singlefield'); __PACKAGE__->mk_group_accessors('multiple', qw/sub_multiple1 sub_multiple2/); __PACKAGE__->mk_group_accessors('listref', [qw/sub_lr1name sub_lr1field/], [qw/sub_lr2name sub_lr2field/]); __PACKAGE__->mk_group_accessors('component_class', 'sub_result_class'); sub overridden { } sub subclass_only { } 1
Subject: Re: [rt.cpan.org #40304] handle Class::Accessor::Grouped properties
Date: Thu, 6 Nov 2008 14:03:36 +0800
To: bug-UML-Class-Simple [...] rt.cpan.org
From: agentzh <agentzh [...] gmail.com>
On Thu, Nov 6, 2008 at 1:12 AM, Dave Howorth via RT <bug-UML-Class-Simple@rt.cpan.org> wrote: Show quoted text
> > OK, here's a second attempt, with some tests. >
Already applied to the SVN head: http://svn.berlios.de/svnroot/repos/umlclass/ If it looks good, I'll make a new release :) If you want a commit bit, please also let me know. Thanks! -agentzh
Subject: Re: [rt.cpan.org #40304] handle Class::Accessor::Grouped properties
Date: Wed, 20 May 2009 08:37:11 +0800
To: bug-UML-Class-Simple [...] rt.cpan.org
From: agentzh <agentzh [...] gmail.com>
On Thu, Nov 6, 2008 at 2:03 PM, agentzh@gmail.com via RT < bug-UML-Class-Simple@rt.cpan.org> wrote: Show quoted text
> Queue: UML-Class-Simple > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=40304 > > > On Thu, Nov 6, 2008 at 1:12 AM, Dave Howorth via RT > <bug-UML-Class-Simple@rt.cpan.org> wrote:
> > > > OK, here's a second attempt, with some tests. > >
> > Already applied to the SVN head: > > http://svn.berlios.de/svnroot/repos/umlclass/ > > If it looks good, I'll make a new release :) >
Already included in the 0.18 CPAN release. (Sorry for the delay.) Thanks! -agentzh