File: 24local_inc_object.t

package info (click to toggle)
libmodule-pluggable-perl 6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: perl: 1,605; makefile: 4
file content (50 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
#!perl -w

use strict;
use FindBin;
use Test::More tests => 5;

eval { require 'Text::BibTex' };
my $bibtex = !$@;

SKIP: {

skip "This test fails when Text::BibTex is installed", 2 if $bibtex;

my $inc  = IncTest->new();
my ($ta) = grep { ref($_) eq 'Text::Abbrev'} eval { local ($^W) = 0; $inc->plugins };
ok($ta);
is($ta->MPCHECK, "HELLO");

ok($inc->before() > 0,'before_instantiate fired');

my %after = $inc->after();
ok(keys %after > 0, 'after_instantiate fired');

my $norefs = scalar grep { ref($_) } values %after;
my $total = scalar values %after;
ok($total == $norefs, 'after_instantiate has all refs');

};

package IncTest;
our @BEFORE;
our %AFTER;

use Module::Pluggable search_path => "Text",
                      search_dirs => "t/lib",
                      instantiate => 'module_pluggable',
                      before_instantiate => sub { push @BEFORE, $_[0]; return 1 },
                      after_instantiate  => sub { $AFTER{$_[0]} = $_[1]; return $_[1] },
                      on_require_error     => sub { },
                      on_instantiate_error => sub { };

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub before { @BEFORE }
sub after { %AFTER }

1;