Posted on 2008-07-29 08:52:31-07 by foobie
Patch to support Class::Accessor::Fast & friends
Just a quickie: Class::Accessor::Fast creates functions for accessing properties - for a property "id" it will create a _id_accessor() and id() function. This patch populates the properties for the class & removes the accessor functions from the functions list.
--- /usr/lib/perl5/site_perl/5.8.5/UML/Class/Simple.pm 2008-07-29 09:21:03.000000000 +0000 +++ Simple_new.pm 2008-07-29 09:20:37.000000000 +0000 @@ -273,6 +273,22 @@ }; my $func = Class::Inspector->functions($pkg); if ($func and @$func) { + + my %functions = map { $_ => 1 } @$func; # create hash from array + my @accessors = grep { /^_.*_accessor$/ } @$func; + foreach my $accessor (@accessors) { + if ($accessor =~ /^_(.*)_accessor$/ ) { + my $property = $1; + if (exists $functions{$property}) { + delete $functions{$property}; + delete $functions{"_${property}_accessor"}; + push @{ $classes[-1]->{properties} }, $property; + } + } + } + @{ $classes[-1]->{properties} } = sort @{ $classes[-1]->{properties} }; + @$func = sort keys(%functions); + if ($public_only) { @$func = grep { /^[^_]/ } @$func; }
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.