?

Log in

No account? Create an account
Pain with perl's method dispatch - brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Pain with perl's method dispatch [Aug. 11th, 2005|11:35 pm]
Brad Fitzpatrick
[Tags|, ]

Update: I think it turned out to be my bug, but Perl 5.8.4 and Perl 5.8.7 handled it differently, which still freaks me out.

Is it safe in Perl to cast references up and down the class hierarchy at runtime? It always appeared to work (on perl 5.8.7), but it doesn't seem to work on perl 5.8.4. I see nothing in the changelogs about this.

Look at this:

1..38
ok 1 - web servers started
beginning run
ok 2 - perlbal started
ok 3 - status response ok
ok 4 - one done
upgrading Perlbal::ClientHTTPBase=ARRAY(0x8839950) to Perlbal::ClientHTTP=ARRAY(0x8839950).
event_read_put for Perlbal::ClientHTTPBase=ARRAY(0x8839950). content_length_remain = 0
-- what? It was just convered down the tree to a ClientHTTP!
ok 5 - Good PUT
ok 6 - two done
ok 7 - file good via disk
crash log: wrong class for Perlbal::ClientHTTPBase=ARRAY(0x8839950) at blib/lib/Perlbal/ClientHTTPBase.pm line 543
-- my assertion that the ref is wrong. should be ref $foo eq "Perlbal::ClientHTTP"
crash log: Perlbal::ClientHTTPBase::put_writeout('Perlbal::ClientHTTPBase=ARRAY(0x8839950)') called at blib/lib/Perlbal/ClientHTTP.pm line 2
56
crash log: Perlbal::ClientHTTP::event_read_put('Perlbal::ClientHTTPBase=ARRAY(0x8839950)') called at blib/lib/Perlbal/ClientHTTP.pm line 80
crash log: Perlbal::ClientHTTP::event_read('Perlbal::ClientHTTPBase=ARRAY(0x8839950)') called at /usr/share/perl5/Danga/Socket.pm line 629

--- look at ite bounce around between ClientHTTP and ClientHTTPBase. ??
crash log: Danga::Socket::PostEventLoop() called at /usr/share/perl5/Danga/Socket.pm line 474
crash log: Danga::Socket::EpollEventLoop('Perlbal::Socket') called at blib/lib/Perlbal.pm line 999
crash log: eval {...} called at blib/lib/Perlbal.pm line 997
crash log: Perlbal::run() called at blib/lib/Perlbal/Test.pm line 124
crash log: Perlbal::Test::start_server('\x{a}LOAD vhosts\x{a}CREATE POOL a\x{a}\x{a}CREATE SERVICE ss\x{a} SET ss.listen...') called at t/3
2-selector.t line 56
ending run
So I'm confused. Is perl's method dispatch cache not being cleared?
LinkReply

Comments:
[User Picture]From: mart
2005-08-12 07:12 am (UTC)

As far as I'm aware, Perl doesn't really give a damn about the class heirarchy. It just looks in the symbol table of whatever package you've blessed your reference onto, then takes a little walk through @ISA.

How are you doing this “casting”? I didn't even know perl had casting!

(Reply) (Thread)
From: edge_walker
2005-08-12 10:09 am (UTC)
Just bless the reference into a new package.
(Reply) (Parent) (Thread)
[User Picture]From: mart
2005-08-12 05:15 pm (UTC)

Well, I guess Perl supports casting if you are willing to call that casting. I wouldn't.

(Reply) (Parent) (Thread)
[User Picture]From: brad
2005-08-12 04:09 pm (UTC)
bless. and yes, I know it walks @ISA. But it feels like Perl's caching the method dispatch mapping a little too long.
(Reply) (Parent) (Thread)
[User Picture]From: taral
2005-08-12 08:38 pm (UTC)
OMG scary.
(Reply) (Thread)
[User Picture]From: brad
2005-08-12 08:43 pm (UTC)
Actually I think it ended up being my bug.
(Reply) (Parent) (Thread)