Skip Menu |

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

Report information
The Basics
Id: 25318
Status: new
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: simon [...] tinhinan.net
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: v0.0.8
Fixed in: (no value)



Subject: :init_get alias for :init_arg and :get only
When writing objects I usually want a get accessor for every object - especially for testing even if nothing else will use it. I usually want a init_arg. I rarely want a set accessor - I consider most attributes read only (and if it were not for testing I probably would not provide a get in many cases - but since get causes no harm the test need out wieghs possible exposure). However since :ATTR specifications must go on one line, fitting everything into 78 chars (I much prefer vi in 80 char wide terms and follow PBP) means I have to compromise and either end up with untidy code that either vi or perltidy tried to break by being helpful - or I use :name and get a set accessor I didn't really want. My personal solution has been to modify the class slightly to provide :init_get functioning in much the same way as :name but only aliasing :init_arg and :get and excluding set. I didn't add one that excludes :get as given my above assertions regards testing it didn't seem appropriate. I'd be grateful if you would consider including the below patch in the next version Simon Day (sorry for the repeated submission but I had been informed that email submissions were frequently ignored on this site due to spam) --- Std.pm.old 2007-02-16 09:12:54.813173000 +0100 +++ Std.pm 2007-02-16 09:16:05.380976000 +0100 @@ -102,19 +102,21 @@ *_extract_get = _extractor_for_pair_named('get'); *_extract_set = _extractor_for_pair_named('set'); *_extract_name = _extractor_for_pair_named('name'); + *_extract_init_get = _extractor_for_pair_named('init_get'); } sub MODIFY_HASH_ATTRIBUTES { my ($package, $referent, @attrs) = @_; for my $attr (@attrs) { next if $attr !~ m/\A ATTRS? \s* (?: \( (.*) \) )? \z/xms; - my ($default, $init_arg, $getter, $setter, $name); + my ($default, $init_arg, $getter, $setter, $name, $init_get); if (my $config = $1) { $default = _extract_default($config); $name = _extract_name($config); - $init_arg = _extract_init_arg($config) || $name; + $init_get = _extract_init_get($config); + $init_arg = _extract_init_arg($config) || $name || $init_get; - if ($getter = _extract_get($config) || $name) { + if ($getter = _extract_get($config) || $name || $init_get) { no strict 'refs'; *{$package.'::get_'.$getter} = sub { return $referent->{ID($_[0])};