Introduce ad hoc requirements and add skip_without method to optdeps
[dbsrgits/DBIx-Class-Historic.git] / t / cdbi / mk_group_accessors.t
CommitLineData
7da06023 1use strict;
4a233f30 2use warnings;
7da06023 3use Test::More;
4
7da06023 5INIT {
50891152 6 use lib 't/cdbi/testlib';
7da06023 7 require Film;
8}
9
10sub Film::get_test {
11 my $self = shift;
12 my $key = shift;
13 $self->{get_test}++;
14 return $self->{$key};
15}
16
17sub Film::set_test {
18 my($self, $key, $val) = @_;
19 $self->{set_test}++;
20 return $self->{$key} = $val;
21}
22
23
24my $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.
39sub Film::accessor_name_for {
40 my($class, $col) = @_;
41 return "hlaglagh" if $col eq "wibble";
42 return $col;
43}
44
45sub 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
62done_testing;