Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I am curious how you ended up using XS---I figure there must be a good story about that. Did comparing them as strings not work for some reason?
    use Test::More tests => 3;
     
    my $a = 5;
    my $b = \$a;
    my $c = \$a;
    my $d = \$b;
     
    my $e = [];
     
    is( $b, $c, "Same scalar data" );
    isnt( $b, $d, "Not the same" );
    isnt( $c, $e, "Not the same" );


    As for names, I would go for Test::Ref, since the Perl operator is ref().

    • It does OK with scalars, but some of the other reference types, no.

      For example,

      use warnings;
      use strict;
      use Test::More tests => 2;

      my $val1 = qr/foo/;
      my $val2 = qr/foo/;

      $a = $val1;
      $b = $val1;
      $c = $val2;

      diag ref $a;
      diag ref $b;
      diag ref $c;

      is($a, $b);
      isnt($a, $c);
  • ref $a and ref $b and $a == $b
    That seems a bit heavy.
    --
    • Randal L. Schwartz
    • Stonehenge
  • What's the problem that you were solving? I'm thinking that maybe this reference matching is really a different problem.
    --

    --
    xoa

    • I am testing to ensure that an object returned by a function is actually the same object received by a previous call to this function. In OO terms, I testing to make sure a class is a Singleton.

      I tried the XS route, until Randal's suggestion above, because I needed the address of what the RV*'s were pointing to. The new route of is((ref $a && ref $b && $a == $b), 1) isn't pretty, but it works just fine. Also, I got a good look at how Test::Builder and Test::Builder::Tester work, so I wou