Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Why is a hash the default "object" in oo perl?

by BUU (Prior)
on Jul 18, 2004 at 09:26 UTC ( [id://375353]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Why is a hash the default "object" in oo perl?
in thread Why is a hash the default "object" in oo perl?

When I am evaluating a module implementation with the idea that I might want to inherit from it, my favorite thing to find is a blessed hashref without a fancy OO-helper module
Untill you accidentally step on your parents key and break stuff that you'll never, ever track down.
  • Comment on Re^3: Why is a hash the default "object" in oo perl?

Replies are listed 'Best First'.
Re^4: Why is a hash the default "object" in oo perl?
by toma (Vicar) on Jul 19, 2004 at 02:47 UTC
    I have stepped on a key before, but it was easy to find with Data::Dumper.

    Now I am in the habit of writing a little test program using the module. The test program uses Data::Dumper so that I can look at the object before writing something that will inherit from it.

    This approach has been satisfactory unless the objects are overly large, complex, or numerous. There are several dimensions to this scalability problem:

    1. Length: The object is really long, such as Data::Dumper output that is more than 10,000 lines long.
    2. Depth: The data structure has too many levels, so that indentation is hard to follow. I typically start to lose insight somewhere between 5 and 10 levels of depth.
    3. Complexity: Since the hash values come out in a non-intuitive order, small things can get lost next to big things.
    However, if I'm doing something this big and complex I usually have the time to do some research to figure it out.

    My approach is not perfect. This may be why I don't use an IS_A relationship when a HAS_A relationship will probably work just as well in my immediate application.

    It should work perfectly the first time! - toma
      I recently just starting using Devel::Peek to look at my data structures. I love it. After reading the module doco you get an idea of the output from Devel::Peek and the structure of what you are seeing. It shows a wealth of data about your objects, hashes, variables, their types, reference counts, length, size, addresses and so on. It will even show what class your objects are blessed into. Very cool!

      Note: It will only show the first 4 elements of a structure unless you specify for it to show more by sending it an additional integer. eg. Devel::Peek::dump(\%hash, 8)

      For example this is 4 element dump of my %hash:
      SV = RV(0x1a7ba4c) at 0x1bd1e98 <<--## a scalar that is a ref REFCNT = 1 <<--## Its ref count FLAGS = (TEMP,ROK) RV = 0x1b5e014 <<--## The ref value SV = PVHV(0x1b25384) at 0x1b5e014 <<--## the scalar ref points to a + hash REFCNT = 2 <<--## The hashes ref count FLAGS = (PADBUSY,PADMY,SHAREKEYS) IV = 1 NV = 0 ARRAY = 0x1a49e84 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 Elt ".*" HASH = 0xaeb62926 <<--## First element of hash SV = RV(0x1a7ba3c) at 0x1bd1e8c <<--## is a scalar ref REFCNT = 1 FLAGS = (ROK) RV = 0x1bce2c4 SV = PVAV(0x1bcb7c4) at 0x1bce2c4 <<--## which points to an arra +y with 5 references REFCNT = 5 FLAGS = () IV = 0 NV = 0 ARRAY = 0x1a49634 FILL = 1 MAX = 1 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 <<--## Element zero of that array SV = PV(0x1b3dbf0) at 0x1bd8098 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1a4980c "return_me"\0 <<--## its value CUR = 9 LEN = 10 Elt No. 1 <<--## ... and so on SV = PV(0x1a6097c) at 0x1bd80b0 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1a49834 "fullfile"\0 CUR = 8
      Anyway, it blows my hair back :-)

      Dean
      The Funkster of Mirth
      Programming these days takes more than a lone avenger with a compiler. - sam
      RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
        Devel::Peek is geared to people debugging perl internals - this isn't the tool you'd normally use when just trying to discover the structure of something. Data::Dumper is the built-in natural for that. demerphq's Data::Dump::Streamer is a separate install but it gets even closer to the actual structure.
Re^4: Why is a hash the default "object" in oo perl?
by diotalevi (Canon) on Jul 19, 2004 at 17:01 UTC

    I've used my subclass package name as a key to a child hash. So while my parent may say $self->{ 'key' } internally, I say $self->{ +__PACKAGE__ }{ 'key' } which works as long as my parent doesn't name their hash keys things like Foo::Bar.

    # A "dumping" of such a structure. $self = { bar => ..., foo => ..., 'Foo::Bar' => { bar => ..., foo => ... } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375353]
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-16 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found