Re: Proposal: Test::Refcount

2008-07-16 Thread Aristotle Pagaltzis
* Paul LeoNerd Evans [EMAIL PROTECTED] [2008-07-14 23:20]: If it still fails, perhaps try my $object = shift; my $count = shift; my $name = shift; that way it'll remove the ref. from @_ as it goes. my ( $object, $count, $name ) = @_; @_ = (); ? Regards, -- Aristotle

Re: Proposal: Test::Refcount

2008-07-16 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 19:16:08 -0700 Joshua ben Jore [EMAIL PROTECTED] wrote: *Devel::RefCount::refcount = \Devel::Peek::SvREFCNT; No it isn't. Devel::Peek::SvREFCNT counts the refcount of the SV itself that is passed to it. Mine counts the refcount of the RV contained in a reference value.

Re: Proposal: Test::Refcount

2008-07-15 Thread Ovid
--- On Mon, 14/7/08, Ivan Wills [EMAIL PROTECTED] wrote: Is this Devel::Refcount really necessary, given how easy it is to build using B::SV-REFCNT ? Plus, the more levels of code, the more difficult it is to ensure the count is correct. I see your point although I would contend

Re: Proposal: Test::Refcount

2008-07-15 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 00:44:12 +0100 Paul LeoNerd Evans [EMAIL PROTECTED] wrote: GLOB = \*SomeNewName, Also, this one isn't a fair test. Any real object code in a module would probably just pass out a new IO handle (as from socket(), socketpair(), pipe(), etc...) or else generate one using

Re: Proposal: Test::Refcount

2008-07-15 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 00:11:10 -0700 (PDT) Ovid [EMAIL PROTECTED] wrote: The B modules are incredibly powerful, poorly documented pieces of crap. They may be great, but without documentation on how to use that speedboat, it's so much scrap metal. So... is this a vote in favour of better docs,

Re: Proposal: Test::Refcount

2008-07-15 Thread Sawyer X
Both! :) On Tue, Jul 15, 2008 at 10:20 AM, Paul LeoNerd Evans [EMAIL PROTECTED] wrote: On Tue, 15 Jul 2008 00:11:10 -0700 (PDT) Ovid [EMAIL PROTECTED] wrote: The B modules are incredibly powerful, poorly documented pieces of crap. They may be great, but without documentation on how to use

Re: Proposal: Test::Refcount

2008-07-15 Thread Ovid
--- On Tue, 15/7/08, Paul LeoNerd Evans [EMAIL PROTECTED] wrote: The B modules are incredibly powerful, poorly documented pieces of crap. They may be great, but without documentation on how to use that speedboat, it's so much scrap metal. So... is this a vote in favour of better docs,

Re: Proposal: Test::Refcount

2008-07-15 Thread Joshua ben Jore
On Tue, Jul 15, 2008 at 6:08 AM, Paul LeoNerd Evans [EMAIL PROTECTED] wrote: I've relented now, and written a Devel::Refcount; see http://search.cpan.org/~pevans/Devel-Refcount-0.01/lib/Devel/Refcount.pm Your function is already core. *Devel::RefCount::refcount = \Devel::Peek::SvREFCNT;

Re: Proposal: Test::Refcount

2008-07-14 Thread Andy Armstrong
On 14 Jul 2008, at 18:12, Paul LeoNerd Evans wrote: No amount of cycle checking in $some_object is going to find this cycle. If the cycled object is one like this; containing the only reference to itself, then almost by definition there's nothing that could be walked for memory cycles.

Re: Proposal: Test::Refcount

2008-07-14 Thread Andy Lester
On Jul 14, 2008, at 12:12 PM, Paul LeoNerd Evans wrote: Does this sound good? Yes, and if it sounds like it would actually supercede Test::Memory::Cycle, I would be glad to abandon T:M:C in favor of yours. xoxo, Andy -- Andy Lester = [EMAIL PROTECTED] = www.petdance.com = AIM:petdance

Re: Proposal: Test::Refcount

2008-07-14 Thread Ivan Wills
use B qw( svref_2object ); sub refcount { my $sv = svref_2object( $_[0] ); return $sv-REFCNT - 1; # Because @_ refers to it too } This sounds like a very good idea to me, I was looking for a module like this in my last job. I would suggest a two modules though say Devel::Refcount

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 05:01:14 +1000 Ivan Wills [EMAIL PROTECTED] wrote: I would suggest a two modules though say Devel::Refcount Is this Devel::Refcount really necessary, given how easy it is to build using B::SV-REFCNT ? Plus, the more levels of code, the more difficult it is to ensure the

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Mon, 14 Jul 2008 13:46:42 -0500 Andy Lester [EMAIL PROTECTED] wrote: Yes, and if it sounds like it would actually supercede Test::Memory::Cycle, I would be glad to abandon T:M:C in favor of yours. OK; see what you think to the attached initial attempt. Not CPANned it yet; will wait and

Re: Proposal: Test::Refcount

2008-07-14 Thread Nicholas Clark
On Mon, Jul 14, 2008 at 08:32:52PM +0100, Paul LeoNerd Evans wrote: sub is_1ref { my ( undef, $name ) = @_; my $count = refcount($_[0]); ... } The $object in the first code creates a second reference, so you have to subtract 1, whereas the @_ array seems special and

Re: Proposal: Test::Refcount

2008-07-14 Thread David Cantrell
On Tue, Jul 15, 2008 at 05:01:14AM +1000, Ivan Wills wrote: This sounds like a very good idea to me, I was looking for a module like this in my last job. I would suggest a two modules though say Devel::Refcount which exports the refcount function and the Test::Refcount for writing tests.

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Mon, 14 Jul 2008 20:59:34 +0100 David Cantrell [EMAIL PROTECTED] wrote: Can't you use Devel::Peek to get the refcount? I use B: use B qw( svref_2object ); my $SV = svref_2object($ref); my $refcount = $SV-REFCNT; -- Paul LeoNerd Evans [EMAIL PROTECTED] ICQ# 4135350 |

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Mon, 14 Jul 2008 20:59:20 +0100 Nicholas Clark [EMAIL PROTECTED] wrote: It would be dangerous to rely on this reference counting behaviour remaining the same. Ah. Then perhaps it may be safer to use the normal my ( $object, $count, $name ) = @_; list assign idiom, then use -REFCNT - 1

Re: Proposal: Test::Refcount

2008-07-14 Thread Ivan Wills
I would suggest a two modules though say Devel::Refcount Is this Devel::Refcount really necessary, given how easy it is to build using B::SV-REFCNT ? Plus, the more levels of code, the more difficult it is to ensure the count is correct. I see your point although I would contend that a

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 06:11:25 +1000 Ivan Wills [EMAIL PROTECTED] wrote: If Paul LeoNerd Evens doesn't want to create the module Devel::Refcount along with Test::Refcount I would be happy to do it my self. Well, it's not that I don't want to as such.. I'm just not sure it's really justified.

Re: Proposal: Test::Refcount

2008-07-14 Thread Ivan Wills
OK; see what you think to the attached initial attempt. I just tried it and the tests fail on anonymous references in t/01count.t and t/02one.t, I'm using perl 5.8.8 on linux if that is of any help. Ivan Wills -- email/jabber: [EMAIL PROTECTED] / / _ _ / \ / | | | | / \/ \_| | |

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 06:33:26 +1000 Ivan Wills [EMAIL PROTECTED] wrote: I just tried it and the tests fail on anonymous references in t/01count.t and t/02one.t, I'm using perl 5.8.8 on linux if that is of any help. Ahh.. 5.10 here. OK; I've changed it to use a normal lexical $object, then

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Mon, 14 Jul 2008 21:42:23 +0100 Paul LeoNerd Evans [EMAIL PROTECTED] wrote: OK; I've changed it to use a normal lexical $object, then subtract 1 from the refcount, rather than rely on @_ not incrementing the count. Perhaps that'll be more portable. Actually it occurs to me this may not

Re: Proposal: Test::Refcount

2008-07-14 Thread Jonathan Rockway
* On Mon, Jul 14 2008, Paul LeoNerd Evans wrote: On Tue, 15 Jul 2008 06:11:25 +1000 Ivan Wills [EMAIL PROTECTED] wrote: If Paul LeoNerd Evens doesn't want to create the module Devel::Refcount along with Test::Refcount I would be happy to do it my self. Well, it's not that I don't want to as

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Mon, 14 Jul 2008 18:28:57 -0500 Jonathan Rockway [EMAIL PROTECTED] wrote: Considering B is core, there is probably no need for a module to do this. But, does this always return correct results? Does the svref_2object call affect the REFCNT? I am too lazy to check, but these are nice

Re: Proposal: Test::Refcount

2008-07-14 Thread Paul LeoNerd Evans
On Tue, 15 Jul 2008 00:44:12 +0100 Paul LeoNerd Evans [EMAIL PROTECTED] wrote: SCALAR = do { \my $var }, It seems I can make the SCALAR ref have refcount 1 by changing this to SCALAR = do { my $var; \$var }, Various initialisations {e.g my $var = 1} also keep it happy. Just the CODE

Re: Proposal: Test::Refcount

2008-07-14 Thread Jonathan Rockway
* On Mon, Jul 14 2008, Paul LeoNerd Evans wrote: On Tue, 15 Jul 2008 00:44:12 +0100 Paul LeoNerd Evans [EMAIL PROTECTED] wrote: SCALAR = do { \my $var }, It seems I can make the SCALAR ref have refcount 1 by changing this to SCALAR = do { my $var; \$var }, Various initialisations