File: 04_object.t

package info (click to toggle)
libclass-trigger-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 200 kB
  • sloc: perl: 154; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 905 bytes parent folder | download | duplicates (2)
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
use strict;
use Test::More tests => 5;

use IO::Scalar;

use lib './t/lib';
use Foo;

ok(Foo->add_trigger(before_foo => sub { print "before_foo\n" }),
   'add_trigger in Foo');

{
    my $foo = Foo->new;
    tie *STDOUT, 'IO::Scalar', \my $out;
    $foo->add_trigger(after_foo => sub { print "after_foo\n" });
    $foo->foo;
    is $out, "before_foo\nfoo\nafter_foo\n";
}

{
    my $foo = Foo->new;
    tie *STDOUT, 'IO::Scalar', \my $out;
    $foo->foo;
    untie *STDOUT;
    is $out, "before_foo\nfoo\n";
}

{
    my $foo = Foo->new;
    tie *STDOUT, 'IO::Scalar', \my $out;
    $foo->add_trigger(after_foo => sub { print "after_foo1\n" });
    $foo->add_trigger(after_foo => sub { print "after_foo2\n" });
    $foo->foo;
    is $out, "before_foo\nfoo\nafter_foo1\nafter_foo2\n";
}

{
    my $foo = Foo->new;
    tie *STDOUT, 'IO::Scalar', \my $out;
    $foo->foo;
    is $out, "before_foo\nfoo\n";
}