A
Alfred Z. Newmane
I noticed when trying to inherit from IO::Select along with a class that
I've written (an event handling class, that uses the moral HASH style
class container, for use with bless.)
A skeleton example of my Event class:
package MyEvent;
use strict;
sub new { # Constructor.
my ($this, $obj) = (
shift,
{ Events => { } }
);
my $class = ref($this) || $this;
return bless $obj, $class;
}
I noticed that IO:Select actually uses an ARRAY ref (blessed), rather
than a HASH ref, to contain itself. Why is this?
It seems to make it rather difficult to inherit from:
1 package MySelect;
2 use strict;
3 use IO::Select;
4 use MyEvent;
5 our @ISA = qw(IO::Select MyEvent);
6
7 sub new {
8 my $this = shift;
9 my $class = ref($this) || $this;
10
11 my $select = new IO::Select(@_);
12 my $event = new MyEvent(@_);
13
14 print "[". ($event), "]\n[". ($select), "]\n";
15
16 my $obj = { @$select, %$event };
17 }
This prints:
[MyEvent=HASH(0x81705e8)]
[IO::Select=ARRAY(0x80fbb4c)]
Use of uninitialized value in anonymous hash ({}) at SR/Select.pm
line 16.
This error message seems a little misleading. Why is it claiming it is
uninitialized? If I remove @$select from that line, then the error no
longer occurs. From the 2nd line of output, it is clear IO::Select is a
blessed ARRAY ref rather than a HASH ref.
* NOTE: These are just a very simplified versions of my classes,
stripped down to the bare minimum that illustrates the problem. I find
that to be infinitely more useful than posting several pages of code
*
What is the best way to go about this? I've never actually ran into a
class that uses an ARRAY as it's internal container. All others I've
encountered all bless a HASH. I was previously unaware that one could
actually bless an ARRAY instead.
Thank you for any insight on this, I find this to be an interesting
topic, which does not appear to have been talked about around before, at
least I could not find anything on this via google groups.
** (And yes I've looked through the FAQs as well as
perltoot/tootc/bot/boot/obj/etc. I pride myself at going to great
lengths to solve my problem before considering, and thought this might
be worthy of bringing up in this group.) **
I've written (an event handling class, that uses the moral HASH style
class container, for use with bless.)
A skeleton example of my Event class:
package MyEvent;
use strict;
sub new { # Constructor.
my ($this, $obj) = (
shift,
{ Events => { } }
);
my $class = ref($this) || $this;
return bless $obj, $class;
}
I noticed that IO:Select actually uses an ARRAY ref (blessed), rather
than a HASH ref, to contain itself. Why is this?
It seems to make it rather difficult to inherit from:
1 package MySelect;
2 use strict;
3 use IO::Select;
4 use MyEvent;
5 our @ISA = qw(IO::Select MyEvent);
6
7 sub new {
8 my $this = shift;
9 my $class = ref($this) || $this;
10
11 my $select = new IO::Select(@_);
12 my $event = new MyEvent(@_);
13
14 print "[". ($event), "]\n[". ($select), "]\n";
15
16 my $obj = { @$select, %$event };
17 }
This prints:
[MyEvent=HASH(0x81705e8)]
[IO::Select=ARRAY(0x80fbb4c)]
Use of uninitialized value in anonymous hash ({}) at SR/Select.pm
line 16.
This error message seems a little misleading. Why is it claiming it is
uninitialized? If I remove @$select from that line, then the error no
longer occurs. From the 2nd line of output, it is clear IO::Select is a
blessed ARRAY ref rather than a HASH ref.
* NOTE: These are just a very simplified versions of my classes,
stripped down to the bare minimum that illustrates the problem. I find
that to be infinitely more useful than posting several pages of code
*
What is the best way to go about this? I've never actually ran into a
class that uses an ARRAY as it's internal container. All others I've
encountered all bless a HASH. I was previously unaware that one could
actually bless an ARRAY instead.
Thank you for any insight on this, I find this to be an interesting
topic, which does not appear to have been talked about around before, at
least I could not find anything on this via google groups.
** (And yes I've looked through the FAQs as well as
perltoot/tootc/bot/boot/obj/etc. I pride myself at going to great
lengths to solve my problem before considering, and thought this might
be worthy of bringing up in this group.) **