r34820 - in /branches/upstream/libdevel-refcount-perl: ./ current/ current/lib/ current/lib/Devel/ current/t/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Tue May 5 23:50:18 UTC 2009


Author: jawnsy-guest
Date: Tue May  5 23:50:12 2009
New Revision: 34820

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=34820
Log:
[svn-inject] Installing original source of libdevel-refcount-perl

Added:
    branches/upstream/libdevel-refcount-perl/
    branches/upstream/libdevel-refcount-perl/current/
    branches/upstream/libdevel-refcount-perl/current/Build.PL
    branches/upstream/libdevel-refcount-perl/current/Changes
    branches/upstream/libdevel-refcount-perl/current/MANIFEST
    branches/upstream/libdevel-refcount-perl/current/META.yml
    branches/upstream/libdevel-refcount-perl/current/Makefile.PL
    branches/upstream/libdevel-refcount-perl/current/lib/
    branches/upstream/libdevel-refcount-perl/current/lib/Devel/
    branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.pm
    branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.xs
    branches/upstream/libdevel-refcount-perl/current/t/
    branches/upstream/libdevel-refcount-perl/current/t/00use.t
    branches/upstream/libdevel-refcount-perl/current/t/01refs.t
    branches/upstream/libdevel-refcount-perl/current/t/02objects.t
    branches/upstream/libdevel-refcount-perl/current/t/03fail.t

Added: branches/upstream/libdevel-refcount-perl/current/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/Build.PL?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/Build.PL (added)
+++ branches/upstream/libdevel-refcount-perl/current/Build.PL Tue May  5 23:50:12 2009
@@ -1,0 +1,25 @@
+use strict;
+use warnings;
+
+use Module::Build;
+
+my $build = Module::Build->new
+  (
+   module_name => 'Devel::Refcount',
+   requires => {
+   },
+   configure_requires => {
+                 'ExtUtils::CBuilder' => 0,
+                 'Module::Build'      => 0,
+   },
+   build_requires => {
+                 'ExtUtils::CBuilder' => 0,
+                 'Module::Build'      => 0,
+                 'Test::Exception'    => 0,
+                 'Test::More'         => 0,
+   },
+   license => 'perl',
+   create_makefile_pl => 'small',
+  );
+  
+$build->create_build_script;

Added: branches/upstream/libdevel-refcount-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/Changes?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/Changes (added)
+++ branches/upstream/libdevel-refcount-perl/current/Changes Tue May  5 23:50:12 2009
@@ -1,0 +1,19 @@
+Revision history for Devel-Refcount
+
+0.04    BUGFIXES:
+         * Declare ExtUtils::CBuilder and Module::Build as configure_requires
+
+0.03    BUGFIXES:
+         * TEMPORARY workaround for bleadperl's behaviour on Regexp references
+         * Declare dependence on ExtUtils::CBuilder
+
+0.02    BUGFIXES:
+         * Make sure Regexp refs have count 1 even on perl 5.11, which seems
+           to share references
+
+        CHANGES:
+         * Expanded documentation about the difference between refcount() and
+           Devel::Peek::SvREFCNT().
+
+0.01    First version, released on an unsuspecting world.
+

Added: branches/upstream/libdevel-refcount-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/MANIFEST?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/MANIFEST (added)
+++ branches/upstream/libdevel-refcount-perl/current/MANIFEST Tue May  5 23:50:12 2009
@@ -1,0 +1,11 @@
+Build.PL
+Changes
+lib/Devel/Refcount.pm
+lib/Devel/Refcount.xs
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+t/00use.t
+t/01refs.t
+t/02objects.t
+t/03fail.t

Added: branches/upstream/libdevel-refcount-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/META.yml?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/META.yml (added)
+++ branches/upstream/libdevel-refcount-perl/current/META.yml Tue May  5 23:50:12 2009
@@ -1,0 +1,25 @@
+---
+name: Devel-Refcount
+version: 0.04
+author:
+  - 'Paul Evans E<lt>leonerd at leonerd.org.ukE<gt>'
+abstract: obtain the REFCNT value of a referent
+license: perl
+resources:
+  license: http://dev.perl.org/licenses/
+configure_requires:
+  ExtUtils::CBuilder: 0
+  Module::Build: 0
+build_requires:
+  ExtUtils::CBuilder: 0
+  Module::Build: 0
+  Test::Exception: 0
+  Test::More: 0
+provides:
+  Devel::Refcount:
+    file: lib/Devel/Refcount.pm
+    version: 0.04
+generated_by: Module::Build version 0.280801
+meta-spec:
+  url: http://module-build.sourceforge.net/META-spec-v1.2.html
+  version: 1.2

Added: branches/upstream/libdevel-refcount-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/Makefile.PL?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/Makefile.PL (added)
+++ branches/upstream/libdevel-refcount-perl/current/Makefile.PL Tue May  5 23:50:12 2009
@@ -1,0 +1,6 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01
+    use Module::Build::Compat 0.02;
+    
+    Module::Build::Compat->run_build_pl(args => \@ARGV);
+    require Module::Build;
+    Module::Build::Compat->write_makefile(build_class => 'Module::Build');

Added: branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.pm?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.pm (added)
+++ branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.pm Tue May  5 23:50:12 2009
@@ -1,0 +1,114 @@
+package Devel::Refcount;
+
+use strict;
+
+use base qw( Exporter );
+use base qw( DynaLoader );
+
+our @EXPORT_OK = qw( refcount );
+
+our $VERSION = '0.04';
+
+__PACKAGE__->bootstrap( $VERSION );
+
+=head1 NAME
+
+C<Devel::Refcount> - obtain the REFCNT value of a referent
+
+=head1 SYNOPSIS
+
+ use Devel::Refcount qw( refcount );
+
+ my $anon = [];
+
+ print "Anon ARRAY $anon has " . refcount($anon) . " reference\n";
+
+ my $otherref = $anon;
+
+ print "Anon ARRAY $anon now has " . refcount($anon) . " references\n";
+
+=head1 DESCRIPTION
+
+This module provides a single function which obtains the reference count of
+the object being pointed to by the passed reference value.
+
+=cut
+
+=head1 FUNCTIONS
+
+=cut
+
+=head2 $count = refcount($ref)
+
+Returns the reference count of the object being pointed to by $ref.
+
+=cut
+
+=head1 COMPARISON WITH SvREFCNT
+
+This function differs from C<Devel::Peek::SvREFCNT> in that SvREFCNT() gives
+the reference count of the SV object itself that it is passed, whereas
+refcount() gives the count of the object being pointed to. This allows it to
+give the count of any referent (i.e. ARRAY, HASH, CODE, GLOB and Regexp types)
+as well.
+
+Consider the following example program:
+
+ use Devel::Peek qw( SvREFCNT );
+ use Devel::Refcount qw( refcount );
+ 
+ sub printcount
+ {
+    my $name = shift;
+ 
+    printf "%30s has SvREFCNT=%d, refcount=%d\n",
+       $name, SvREFCNT($_[0]), refcount($_[0]);
+ }
+ 
+ my $var = [];
+
+ printcount 'Initially, $var', $var;
+ 
+ my $othervar = $var;
+
+ printcount 'Before CODE ref, $var', $var;
+ printcount '$othervar', $othervar;
+ 
+ my $code = sub { undef $var };
+ 
+ printcount 'After CODE ref, $var', $var;
+ printcount '$othervar', $othervar;
+
+This produces the output
+
+                Initially, $var has SvREFCNT=1, refcount=1
+          Before CODE ref, $var has SvREFCNT=1, refcount=2
+                      $othervar has SvREFCNT=1, refcount=2
+           After CODE ref, $var has SvREFCNT=2, refcount=2
+                      $othervar has SvREFCNT=1, refcount=2
+
+Here, we see that SvREFCNT() counts the number of references to the SV object
+passed in as the scalar value - the $var or $othervar respectively, whereas
+refcount() counts the number of reference values that point to the referent
+object - the anonymous ARRAY in this case.
+
+Before the CODE reference is constructed, both $var and $othervar have
+SvREFCNT() of 1, as they exist only in the current lexical pad. The anonymous
+ARRAY has a refcount() of 2, because both $var and $othervar store a reference
+to it.
+
+After the CODE reference is constructed, the $var variable now has an
+SvREFCNT() of 2, because it also appears in the lexical pad for the new
+anonymous CODE block.
+
+=cut
+
+# Keep perl happy; keep Britain tidy
+1;
+
+__END__
+
+=head1 AUTHOR
+
+
+Paul Evans E<lt>leonerd at leonerd.org.ukE<gt>

Added: branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.xs
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.xs?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.xs (added)
+++ branches/upstream/libdevel-refcount-perl/current/lib/Devel/Refcount.xs Tue May  5 23:50:12 2009
@@ -1,0 +1,17 @@
+#include "EXTERN.h"
+#include "perl.h"
+#include "XSUB.h"
+
+MODULE = Devel::Refcount    PACKAGE = Devel::Refcount
+
+int
+refcount(ref)
+  SV *ref
+
+  CODE:
+    if(!SvROK(ref)) {
+      croak("ref is not a reference");
+    }
+    RETVAL = SvREFCNT(SvRV(ref));
+  OUTPUT:
+    RETVAL

Added: branches/upstream/libdevel-refcount-perl/current/t/00use.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/t/00use.t?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/t/00use.t (added)
+++ branches/upstream/libdevel-refcount-perl/current/t/00use.t Tue May  5 23:50:12 2009
@@ -1,0 +1,5 @@
+#!/usr/bin/perl -w
+
+use Test::More tests => 1;
+
+use_ok( "Devel::Refcount" );

Added: branches/upstream/libdevel-refcount-perl/current/t/01refs.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/t/01refs.t?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/t/01refs.t (added)
+++ branches/upstream/libdevel-refcount-perl/current/t/01refs.t Tue May  5 23:50:12 2009
@@ -1,0 +1,61 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 12;
+
+use Devel::Refcount qw( refcount );
+
+use Symbol qw( gensym );
+
+my %refs = (
+   SCALAR => do { my $var; \$var },
+   ARRAY  => [],
+   HASH   => +{},
+   # This magic is to ensure the code ref is new, not shared. To be a new one
+   # it has to contain a unique pad.
+   CODE   => do { my $var; sub { $var } },
+   GLOB   => gensym(),
+   Regexp => do { my $var; qr/foo(?{ $var = 1 })/ },
+);
+
+is( refcount($refs{SCALAR}), 1, 'refcount(SCALAR) is 1');
+is( refcount($refs{ARRAY}),  1, 'refcount(ARRAY) is 1');
+is( refcount($refs{HASH}),   1, 'refcount(HASH) is 1');
+is( refcount($refs{CODE}),   1, 'refcount(CODE) is 1');
+is( refcount($refs{GLOB}),   1, 'refcount(GLOB) is 1');
+
+SKIP: {
+   if( $] >= 5.011 ) {
+      # Perl v5.11 seems to have odd behaviour with Regexp references. They start
+      # off with a refcount of 2. Not sure if this is a bug in Perl, or my
+      # assumption. Until P5P have worked it out, we'll skip this, but just print
+      # a diagnostic
+      diag( "On Perl $], refcount(\$refs{Regexp}) is ".refcount($refs{Regexp}) );
+      skip "Bleadperl", 1;
+   }
+
+   is( refcount($refs{Regexp}), 1, 'refcount(Regexp) is 1');
+}
+
+my %otherrefs = %refs;
+# Hope they're all 2 now
+
+is( refcount($refs{SCALAR}), 2, 'refcount(SCALAR) is now 2');
+is( refcount($refs{ARRAY}),  2, 'refcount(ARRAY) is now 2');
+is( refcount($refs{HASH}),   2, 'refcount(HASH) is now 2');
+is( refcount($refs{CODE}),   2, 'refcount(CODE) is now 2');
+is( refcount($refs{GLOB}),   2, 'refcount(GLOB) is now 2');
+
+SKIP: {
+   if( $] >= 5.011 ) {
+      # Perl v5.11 seems to have odd behaviour with Regexp references. They start
+      # off with a refcount of 2. Not sure if this is a bug in Perl, or my
+      # assumption. Until P5P have worked it out, we'll skip this, but just print
+      # a diagnostic
+      diag( "On Perl $], refcount(\$refs{Regexp}) is ".refcount($refs{Regexp}) );
+      skip "Bleadperl", 1;
+   }
+
+   is( refcount($refs{Regexp}),  2, 'refcount(Regexp) is now 2');
+}

Added: branches/upstream/libdevel-refcount-perl/current/t/02objects.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/t/02objects.t?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/t/02objects.t (added)
+++ branches/upstream/libdevel-refcount-perl/current/t/02objects.t Tue May  5 23:50:12 2009
@@ -1,0 +1,63 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 12;
+
+use Devel::Refcount qw( refcount );
+
+use Symbol qw( gensym );
+
+my %refs = (
+   SCALAR => do { my $var; \$var },
+   ARRAY  => [],
+   HASH   => +{},
+   # This magic is to ensure the code ref is new, not shared. To be a new one
+   # it has to contain a unique pad.
+   CODE   => do { my $var; sub { $var } },
+   GLOB   => gensym(),
+   Regexp => do { my $var; qr/foo(?{ $var = 1 })/ },
+);
+
+bless $_, "Some::Package" for values %refs;
+
+is( refcount($refs{SCALAR}), 1, 'refcount(SCALAR) is 1');
+is( refcount($refs{ARRAY}),  1, 'refcount(ARRAY) is 1');
+is( refcount($refs{HASH}),   1, 'refcount(HASH) is 1');
+is( refcount($refs{CODE}),   1, 'refcount(CODE) is 1');
+is( refcount($refs{GLOB}),   1, 'refcount(GLOB) is 1');
+
+SKIP: {
+   if( $] >= 5.011 ) {
+      # Perl v5.11 seems to have odd behaviour with Regexp references. They start
+      # off with a refcount of 2. Not sure if this is a bug in Perl, or my
+      # assumption. Until P5P have worked it out, we'll skip this, but just print
+      # a diagnostic
+      diag( "On Perl $], refcount(\$refs{Regexp}) is ".refcount($refs{Regexp}) );
+      skip "Bleadperl", 1;
+   }
+
+   is( refcount($refs{Regexp}), 1, 'refcount(Regexp) is 1');
+}
+
+my %otherrefs = %refs;
+# Hope they're all 2 now
+
+is( refcount($refs{SCALAR}), 2, 'refcount(SCALAR) is now 2');
+is( refcount($refs{ARRAY}),  2, 'refcount(ARRAY) is now 2');
+is( refcount($refs{HASH}),   2, 'refcount(HASH) is now 2');
+is( refcount($refs{CODE}),   2, 'refcount(CODE) is now 2');
+is( refcount($refs{GLOB}),   2, 'refcount(GLOB) is now 2');
+
+SKIP: {
+   if( $] >= 5.011 ) {
+      # Perl v5.11 seems to have odd behaviour with Regexp references. They start
+      # off with a refcount of 2. Not sure if this is a bug in Perl, or my
+      # assumption. Until P5P have worked it out, we'll skip this, but just print
+      # a diagnostic
+      diag( "On Perl $], refcount(\$refs{Regexp}) is ".refcount($refs{Regexp}) );
+      skip "Bleadperl", 1;
+   }
+
+   is( refcount($refs{Regexp}),  2, 'refcount(Regexp) is now 2');
+}

Added: branches/upstream/libdevel-refcount-perl/current/t/03fail.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libdevel-refcount-perl/current/t/03fail.t?rev=34820&op=file
==============================================================================
--- branches/upstream/libdevel-refcount-perl/current/t/03fail.t (added)
+++ branches/upstream/libdevel-refcount-perl/current/t/03fail.t Tue May  5 23:50:12 2009
@@ -1,0 +1,17 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 3;
+use Test::Exception;
+
+use Devel::Refcount qw( refcount );
+
+dies_ok( sub { refcount() },
+         'refcount with no args fails' );
+
+dies_ok( sub { refcount(undef) },
+         'refcount with undef arg fails' );
+
+dies_ok( sub { refcount("hello") },
+         'refcount with non-ref arg fails' );




More information about the Pkg-perl-cvs-commits mailing list