fields pragma

L

Lee Goddard

Is it possible to use the fields pragma to specify the type of each
object member/field?

If not, is there a modulelist module which allows this to be done?

tia
lee
 
A

Anno Siegel

Lee Goddard said:
Is it possible to use the fields pragma to specify the type of each
object member/field?

What does the documentation say? "perldoc fields".

I'm not sure what you mean with "type of field". Do you want to distinguish
strings, integers, floats? Or want to allow only certain kinds of refs
(hash, array, code)? Or only objects of certain classes? Something else?
If not, is there a modulelist module which allows this to be done?

Define "this". If with "types" you mean numeric types, check out PDL.

Anno
 
L

Lee Goddard

What does the documentation say? "perldoc fields".

From what I understand, it impliments object fields using arrays, so
could never support what I'm after, as below:

I'm not sure what you mean with "type of field". Do you want to distinguish
strings, integers, floats? Or want to allow only certain kinds of refs
(hash, array, code)? Or only objects of certain classes? Something else?


Define "this". If with "types" you mean numeric types, check out PDL.

Thanks, Anno: that's the only thing I'm not after, which is basic
implimentation instantiating the fields with given perl types, either
scalars or references. Instances of objects would be nice, too, but
not something I need today.

I tried declaring my own global fields hash and instantiating objects
from it, but of course, setting a field to instantiate to an anonymous
hash/array is setting the field in every instance of the object to
refer to the same anonymous hash/array.

So I wrote the necessary code to get around this (check type of ref,
create new anon thingy), but it seems so necessary that I thought
there might be a pragma for it.

Perhaps the Class::* modules do this, but I'm scared of the overhead.

Lee
 
A

Anno Siegel

Lee Goddard said:
(e-mail address removed)-berlin.de (Anno Siegel) wrote in message


From what I understand, it impliments object fields using arrays, so
could never support what I'm after, as below:



Thanks, Anno: that's the only thing I'm not after, which is basic
implimentation instantiating the fields with given perl types, either
^^^^^^^^^^
"Perl types" is not a recognized part of Perl terminology. My question
is what you mean by it, but instead of explaining you use it as if it
*was* an explanation.
scalars or references. Instances of objects would be nice, too, but
not something I need today.

Oh man... Now which is what you want and which is what you don't want?
I tried declaring my own global fields hash and instantiating objects
from it, but of course, setting a field to instantiate to an anonymous
hash/array is setting the field in every instance of the object to
refer to the same anonymous hash/array.

Again you're using undefined terms as if they had a definite meaning.
What is "setting a field to instantiate to (something)"? I don't have
the slightest idea what you might have done. Show some code instead
of using undefined terms to explain another undefined terms.

Same hash/array: That would depend on how you do it. If you create a
new hash each time, you'll have different hashes. If you take a
reference to the same hash each time, they'll all point to the same one.
So I wrote the necessary code to get around this (check type of ref,
create new anon thingy), but it seems so necessary that I thought
there might be a pragma for it.

Why do you think this so necessary? I have rarely felt the need to
check object fields for their content. If I do, I put a check in the
accessor for that field and that's it. Nor is it necessary to preset
a field that is going to hold an array (say) to an arrayref. Leave the
field unspecified, then autovivification will initialize it to the
right thing on first access.

I don't think we're getting anywhere this way. Show some code that
demonstrates what you want to do. If there's a popular module or
pragma that does something similar, people will know and tell you.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top