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