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