File: 07-adopt-syntax.t

package info (click to toggle)
libvalidation-class-perl 7.900058-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,536 kB
  • sloc: perl: 21,493; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 911 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
use FindBin;
use Test::More;
use utf8;
use strict;
use warnings;

{
    use_ok 'Validation::Class';
}
{

    package TestClass::A;
    use Validation::Class;

    field name  => {mixin => ':str'};
    field color => {mixin => ':str'};
    field year  => {mixin => ':str'};

    method redish_brown => {
        input => ['color'],
        using => sub { 1 }
    };

    package TestClass::B;
    use Validation::Class;

    adopt 'TestClass::A', 'field',  'name';
    adopt 'TestClass::A', 'field',  'color';
    adopt 'TestClass::A', 'method', 'redish_brown';

    package main;

    my $b = TestClass::B->new(color => 'red');

    ok "TestClass::B" eq ref $b, "TestClass::B instantiated";
    ok $b->proto->fields->has($_) => "TestClass::B has $_" for qw(name color);
    can_ok $b, qw(name color redish_brown);
    ok $b->redish_brown() => "TestClass::B redish_brown executed and valid";

}

done_testing();