E
Eckstein C.
Take this code:
(The above is just an example, and only for the purposes of my question,
more below.)
The /actual/ class and construction code are out of my hands (generated
by COM objects or sorts,) in a program that allows for Perl scripting,
mostly used for event handling, and provides "built in" objects, such as
$Server (Server object for the script's context), $Window (currrent
Window object), etc.
Ok, here is ever my question comes in. "read only properties" are member
subs, ie $Server->Name;, while "read/write properties" are
$Server->{SomeProp};
What I want to do is go through each "property" of a given $Obj and
(dynamically) create a (lvalue) sub for each one (added to the
"properties" object of course.)
OR
sub SomeProp : lvalue { $_[0]->{'SomeProp'}; }
Is this possible? (Without using eval, as the scripts in this app seem
to be wrapped in a eval behind the scenes, evident when theres an error
in the code, in the error mesages. )
Thanks.
Code:
package SomeClass;
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $obj; # { Val = 1 };
$obj->{'SomeProp1'} = '';
$obj->{'SomeProp2'} = '';
bless $obj, $class;
return $obj;
}
package main;
print "<pre>" if $ENV{'HTTP_HOST'};
my $c = new SomeClass;
(The above is just an example, and only for the purposes of my question,
more below.)
The /actual/ class and construction code are out of my hands (generated
by COM objects or sorts,) in a program that allows for Perl scripting,
mostly used for event handling, and provides "built in" objects, such as
$Server (Server object for the script's context), $Window (currrent
Window object), etc.
Ok, here is ever my question comes in. "read only properties" are member
subs, ie $Server->Name;, while "read/write properties" are
$Server->{SomeProp};
What I want to do is go through each "property" of a given $Obj and
(dynamically) create a (lvalue) sub for each one (added to the
"properties" object of course.)
Code:
sub SomeProp : lvalue {
my $this = shift;
$this->{'SomeProp'};
}
OR
sub SomeProp : lvalue { $_[0]->{'SomeProp'}; }
Is this possible? (Without using eval, as the scripts in this app seem
to be wrapped in a eval behind the scenes, evident when theres an error
in the code, in the error mesages. )
Thanks.