File: 10-build-method.t

package info (click to toggle)
libvalidation-class-perl 7.900057-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,572 kB
  • ctags: 355
  • sloc: perl: 21,493; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (5)
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
BEGIN {

    use FindBin;
    use lib $FindBin::Bin . "/myapp/lib";

}

use utf8;
use Test::More;

{

    # testing the build method
    # this method is designed to hook into the class instantiation processs

    package MyApp;

    use Validation::Class;

    has number => 0;

    my $incrementer = sub {

        my ($self) = @_;

        $self->number($self->number + 1);

    };

    build $incrementer;

    __PACKAGE__->bld($incrementer);

    package main;

    my $class = "MyApp";
    my $self  = $class->new();

    ok $class eq ref $self, "$class instantiated";

    ok 2 == $self->number, 'the number attribute has been incremented on init';

}

done_testing;