File: Assert.pm

package info (click to toggle)
libalt-perl 0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 168 kB
  • ctags: 14
  • sloc: perl: 89; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 967 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use strict; use warnings;
package Alt::Assert;

sub assert {
    my $self  = shift;
    my $mod   = shift || caller();

    my ($orig, $phrase) = $mod =~ /^Alt::(\w+(?:::\w+)*)::(\w+)$/
        or die "Bad syntax in alternate module name '$mod', should be ".
            "Alt::<Original::Module>::<phrase>\n";
    my $origf = $orig;
    $origf =~ s!::!/!g; $origf .= ".pm";
    require $origf; # if user hasn't loaded the module, load it for them

    defined(&{"$orig\::ALT"})
        or die "$orig does not define ALT, might not be from the same ".
            "distribution as $mod\n";

    my $alt = $orig->ALT;
    $alt eq $phrase
        or die "$orig has ALT set to '$alt' instead of '$phrase', ".
            "might not be from the same distribution as $mod\n";
}

sub import {
    my $self   = shift;
    my $caller = caller();

    # export assert()
    {
        no strict;
        *{"$caller\::assert"} = \&assert;
    }
    $self->assert($caller);
}

1;