Skip to content

Commit

Permalink
Add the ;rand tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwern committed Jun 28, 2009
1 parent da0f54a commit 9eea77a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -5,4 +5,5 @@ MANIFEST This list of files
MANIFEST.SKIP
t/00compile.t
t/control_rand.t
t/exports.t
t/rand.t
8 changes: 6 additions & 2 deletions lib/Test/Sims.pm
Expand Up @@ -127,8 +127,12 @@ sub make_rand {

{
no strict 'refs';
*{$caller . '::rand_' . $name} = $code;
push @{$caller . '::EXPORT_OK'}, "rand_$name";
my $func = "rand_$name";
*{$caller .'::'. $func} = $code;
push @{$caller . '::EXPORT_OK'}, $func;

my $export_tags = \%{ $caller . '::EXPORT_TAGS' };
push @{$export_tags->{"rand"}}, $func;
}

return $code;
Expand Down
72 changes: 72 additions & 0 deletions t/exports.t
@@ -0,0 +1,72 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

# A class without any other exports.
{
package Flowers;
use Test::Sims;

make_rand flower => [qw(Rose Daisy Ed Bob)];
make_rand numbers => [qw(1 2 3 4 5)];
}

# A class which already has exports
{
package Things;
use Test::Sims;

use base "Exporter";
our @EXPORT_OK = "stuff";

sub stuff { 42 }

make_rand stuff => [qw(this that other thing)];
}


# Test :rand export tag
{
package Foo;

Flowers->import(":rand");

::can_ok(__PACKAGE__, "rand_flower");
::can_ok(__PACKAGE__, "rand_numbers");
}


# Test rand functions are in @EXPORT_OK
{
package Bar;

Flowers->import("rand_flower");

::can_ok(__PACKAGE__, "rand_flower");
}


# Test rand functions are not exported by default.
{
package Baz;

Flowers->import();

::ok( !Baz->can("rand_flower"), "does not export rand by default" );
}


# Test existing exports are preserved
{
package Wiffle;

Things->import("stuff", "rand_stuff");

::is( stuff(), 42, "\@EXPORT_OK preserved" );
::can_ok( Wiffle => "rand_stuff" );
}

done_testing();

0 comments on commit 9eea77a

Please sign in to comment.