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.
  • Hopefully it wasn't my slides [redhotpenguin.com] that were way off ;-) Here's how I poked at the internals of a program, including global variables. I got the idea from another post here on use Perl, and I hacked out this working program and test.

    phred@pooky ~ $ cat program.pl
    #!perl -w

    use strict;
    use warnings;

    our $var = 0;

    sub addition {
        my ($one, $other_one) = @_;
        my $result = $one + $other_one+$var;
        return $result;
    }

    sub should_die {
        die "oops";
    }

    1;

    phred@pooky ~ $ cat foo.t
    #!perl

    use strict;
    use warnings FATAL => 'all';

    use Test::More tests => 3;

    my $class = 'program';
    require_ok("$class.pl");
    import $class qw( addition should_die);

    no strict 'refs';
    ${"main\:\:var"} = 5;
    my $method = 'addition';
    cmp_ok($method->(1,1), '==', 7, '1+1+var returns 7');

    $method = 'should_die';
    eval { $method->() };
    like($@, qr/oops/i, 'should_die() died');
    • Oops, I forgot the output

      phred@pooky ~ $ perl foo.t
      1..3
      ok 1 - require 'program.pl';
      ok 2 - 1+1+var returns 7
      ok 3 - should_die() died