Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Cross reference between two classes and FIELDS

by shmem (Chancellor)
on Sep 26, 2006 at 10:10 UTC ( [id://574899]=note: print w/replies, xml ) Need Help??


in reply to Cross reference between two classes and FIELDS

Hmm.. your package C isn't fit for use:
package C; use strict; use base qw(model type); 1; __END__ $ perl -e 'use C' Base class package "model" is empty. (Perhaps you need to 'use' the module which defines that package f +irst.) at C.pm line 5 BEGIN failed--compilation aborted at C.pm line 5.

Working code to scrutinize would help to help.

Apart from that, you might want to have a look at Spiffy.

package A; use Spiffy -Base; use strict; field $_ for qw(id name); sub new { bless {}, $self }
package B; use A -Base; use strict; field $_ for qw(addr phone city); sub new { bless {}, $self }
package C; use A -Base; use strict; field $_ for qw(model type); sub new { bless {}, $self }
#!/usr/bin/perl use strict; use B; use C; use Data::Dumper; $Data::Dumper::Indent = 1; my $foo = new C; $foo->id(123); $foo->name("thingy"); $foo->model("Z80"); my $bar = new B; $bar->id(456); $bar->city("Lhasa"); $bar->name("kouxuan"); print Dumper($foo); print Dumper($bar); __END__ $VAR1 = bless( { 'model' => 'Z80', 'name' => 'thingy', 'id' => 123 }, 'C' ); $VAR1 = bless( { 'city' => 'Lhasa', 'name' => 'kouxuan', 'id' => 456 }, 'B' );

Spiffy rocks ;-)

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: Cross reference between two classes and FIELDS
by nite_man (Deacon) on Sep 26, 2006 at 11:03 UTC

    Yes, your right. It's mistake. It should be:

    use base qw(A); use fields qw(model type);

    ---
    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://574899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found