I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2006-01-24 23:26:04-08 by je44ery
C++ Equiv of Protected?
I like how in C++ child classes inherit parent attributes/fields/members.
class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b;} }; class CRectangle: public CPolygon { public: int area () { return (width * height); } };
In this case, the CRectangle just starts using width & height without declaring it. How possible will this be to do in OIO? I've tried this:
$ cat test_me.pl #!/usr/bin/perl -w use strict; use warnings; use Top::Middle; my $obj = Top::Middle->new( 'info' => 'some_data_or_whatever' ); $obj->method(); exit 0; $ cat Top.pm use strict; use warnings; package Top; use Object::InsideOut; my @info :Field('Standard' => 'info'); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); 1; $ cat Top/Middle.pm use warnings; use strict; package Top::Middle; use Object::InsideOut 'Top'; sub method { my $self = shift; my $string = $info[$$self]; print "$string\n"; } 1;
But I get this:
# ./test_me.pl Global symbol "@info" requires explicit package name at Top/Middle.pm line 12. Compilation failed in require at ./test_me.pl line 6. BEGIN failed--compilation aborted at ./test_me.pl line 6.
If I start using Exporter, which doesn't seem right, it doesn't work either.
$ cat Top.pm use strict; use warnings; package Top; use Object::InsideOut 'Exporter'; BEGIN { our @EXPORT_OK = qw(@info); } my @info :Field('Standard' => 'info'); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); 1; $ cat Top/Middle.pm use warnings; use strict; package Top::Middle; use Object::InsideOut 'Top' => [ qw(@info) ]; sub method { my $self = shift; my $string = $info[$$self]; print "$string\n"; } 1;
This is the result then:
# ./test_me.pl Use of uninitialized value in concatenation (.) or string at Top/Middle.pm line 13.
Direct Responses: 1701 | Write a response
Posted on 2006-01-25 02:15:48-08 by jdhedden in response to 1699
Re: C++ Equiv of Protected?
One class cannot (and shouldn't be forced to) share the lexical field arrays/hashes with derived classes. You have to use the accessors.

The equivalent of 'protected' on C++ member variables is to use 'restricted' accessor methods:
package Top; { use Object::InsideOut; my @info :Field('Std' => 'info', 'Restricted' => 1); my %init_args :InitArgs = ( 'INFO' => { 'Field' => \@info, }, ); } package Top::Middle; { use Object::InsideOut 'Top'; sub print_info { my $self = shift; print($self->get_info(), "n"); } } package main; my $obj = Top::Middle->new('INFO' => 'Some info'); # print($obj->get_info, "\n"); # Can't call restricted accessor $obj->print_info();
Direct Responses: Write a response