Commit | Line | Data |
7da06023 |
1 | use strict; |
2 | use Test::More; |
3 | |
7da06023 |
4 | INIT { |
50891152 |
5 | use lib 't/cdbi/testlib'; |
7da06023 |
6 | require Film; |
7 | } |
8 | |
9 | sub Film::get_test { |
10 | my $self = shift; |
11 | my $key = shift; |
12 | $self->{get_test}++; |
13 | return $self->{$key}; |
14 | } |
15 | |
16 | sub Film::set_test { |
17 | my($self, $key, $val) = @_; |
18 | $self->{set_test}++; |
19 | return $self->{$key} = $val; |
20 | } |
21 | |
22 | |
23 | my $film = Film->create({ Title => "No Wolf McQuade" }); |
24 | |
25 | # Test mk_group_accessors() with a list of fields. |
26 | { |
27 | Film->mk_group_accessors(test => qw(foo bar)); |
28 | $film->foo(42); |
29 | is $film->foo, 42; |
30 | |
31 | $film->bar(23); |
32 | is $film->bar, 23; |
33 | } |
34 | |
35 | |
36 | # An explicit accessor passed to mk_group_accessors should |
37 | # ignore accessor/mutator_name_for. |
38 | sub Film::accessor_name_for { |
39 | my($class, $col) = @_; |
40 | return "hlaglagh" if $col eq "wibble"; |
41 | return $col; |
42 | } |
43 | |
44 | sub Film::mutator_name_for { |
45 | my($class, $col) = @_; |
46 | return "hlaglagh" if $col eq "wibble"; |
47 | return $col; |
48 | } |
49 | |
50 | |
51 | # Test with a mix of fields and field specs |
52 | { |
53 | Film->mk_group_accessors(test => ("baz", [wibble_thing => "wibble"])); |
54 | $film->baz(42); |
55 | is $film->baz, 42; |
56 | |
57 | $film->wibble_thing(23); |
58 | is $film->wibble_thing, 23; |
59 | } |
89bddb49 |
60 | |
61 | done_testing; |