Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: use fields;

by Corion (Patriarch)
on Nov 23, 2004 at 07:19 UTC ( [id://409826]=note: print w/replies, xml ) Need Help??


in reply to use fields;

Is there a reason why you are using that weird syntax instead of the way proposed in the SYNOPSIS section of the documentation ?

package Bar; use base 'Foo'; use fields qw(baz _Bar_private); # not shared with Foo sub new { my $class = shift; my $self = fields::new($class); $self->SUPER::new(); # init base fields $self->{baz} = 10; # init own fields $self->{_Bar_private} = "this is Bar's secret"; return $self; }

Of course, doing it that way means you need to chain to the previous constructor manually, but I didn't see any chaining in your (more generic?) constructor.

Replies are listed 'Best First'.
Re^2: use fields;
by nite_man (Deacon) on Nov 23, 2004 at 08:05 UTC
    Thanks, Corion, you are right, there is not any reason to use the weird syntax. I found it two years ago in the book <a href=;http://www.manning.com/Conway/index.html'>Object Oriented Perl by Damian Conway (in my opinion, that book is one of the best Perl books). Probably, that syntax became old. Unfortunately, using
    my $self = fields::new($class);
    intead of
    no strict "refs"; my $self = bless [\%{"${caller}::FIELDS"}], $class;
    doen't resolve problem with pseudo-hashes.

    ---
    Michael Stepanov aka nite_man

    It's only my opinion and it doesn't have pretensions of absoluteness!

      Re-reading the documentation, Perl 5.8.x still uses the pseudo-hash implementation, so I guess you will have to temporarily switch off the warnings for that section of code:

      my $self = do { no warnings 'deprecated'; fields::new($class); };

        I know that. It worryes me that after month or year Perl developers team will decide to forbid using pseudo hashes.

        So, I'm trying to find a way to produce a good code, probably without problems in the future.

        ---
        Michael Stepanov aka nite_man

        It's only my opinion and it doesn't have pretensions of absoluteness!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://409826]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found