Subject: | Cannot use class constructor :Restricted/:Private attributes *without* parenthetical exemptions |
Basically, if I want to define a class with a restricted (or private)
constructor using the :Restricted (or :Private) attribute, like this:
use Object::InsideOut qw( :Restricted );
with version 3.11 I get an exception (similar to that included as file
test.error) telling me that I cannot load the package named
':Restricted' (or ':Private', as the case may be). The attached file
test.pl is the exact script used to produce test.error, which should
illustrate my point.
I can avoid the exception and things will work as expected if I include
parentheses with no class exemptions, like this:
use Object::InsideOut qw( :Restricted() )
I think an addition of an additional set of non-capturing parentheses in
two particular regular expressions will fix this behavior. The file
class_restrictions.patch includes this fix.
Here's some system info for the sake of utter completeness:
--
Linux nymeria 2.6.19-gentoo-r5 #4 SMP PREEMPT Tue Feb 27 22:22:42 EST
2007 i686 Intel(R) Pentium(R) 4 CPU 3.40GHz GenuineIntel GNU/Linux
perl, v5.8.8 built for i686-linux-thread-multi-ld
--
The exact same behavior occurs in Solaris 2.8, so I believe it should be
system independent.
Subject: | class_restrictions.patch |
*** InsideOut.original Wed Mar 14 23:17:30 2007
--- InsideOut.new Wed Mar 14 23:19:38 2007
***************
*** 211,217 ****
}
# Restricted class
! if ($pkg =~ /^:RESTRICT(?:ED)?\((.*)\)/i) {
*{$class.'::new'}
= wrap_RESTRICTED($class, 'new',
sub { goto &Object::InsideOut::new },
--- 211,217 ----
}
# Restricted class
! if ($pkg =~ /^:RESTRICT(?:ED)?(?:\((.*)\))?/i) {
*{$class.'::new'}
= wrap_RESTRICTED($class, 'new',
sub { goto &Object::InsideOut::new },
***************
*** 223,229 ****
}
# Private class
! if ($pkg =~ /^:PRIV(?:ATE)?\((.*)\)/i) {
*{$class.'::new'}
= wrap_PRIVATE($class, 'new',
sub { goto &Object::InsideOut::new },
--- 223,229 ----
}
# Private class
! if ($pkg =~ /^:PRIV(?:ATE)?(?:\((.*)\))?/i) {
*{$class.'::new'}
= wrap_PRIVATE($class, 'new',
sub { goto &Object::InsideOut::new },
Subject: | test.pl |
#!/opt/bin/perl
package Foo;
# a class which should be restricted
{
use Object::InsideOut qw( :Restricted );
my @response :Field
:Arg( 'response' )
;
sub respond {
my ( $self ) = @_;
print "Foo responds \"", $response[ $$self ], "\"\n";
return scalar 1;
}
}
package Bar;
# inherits from Foo and attempts to define an object of class Foo, failing...
{
use Object::InsideOut qw( :Public Foo );
my @question :Field
:Arg( 'question' )
;
sub ask {
my ( $self ) = @_;
print "Bar asks \"", $question[ $$self ], "\"\n";
my $temp_object = Foo->new( 'response' => 'kapow!' );
$temp_object->respond;
return scalar 1;
}
}
package main;
my $thing = Bar->new( 'question' => 'say wha?' );
$thing->ask;
Subject: | test.error |
Message body not shown because it is not plain text.