fixed the pod for add_child. This function does not take any arguments. it generates...
[cxgn-corelibs.git] / t / CXGN / Class / methodmaker.t
blobf8fd11dbfa84f49261d6b5792bb338400b0938da
1 #!/usr/bin/perl
3 package Foo;
4 use CXGN::Class::MethodMaker [
5 scalar => [qw/
6 these
7 are
8 scalarish
9 /,
10 {-default => "3"},
11 'methods',
12 {-type => "CXGN::DB::Connection",
13 -forward => [qw/prepare execute/]
15 'dbh',
16 qw/ -static static_var /,
20 sub new { bless {}, shift }
24 use Test::More tests => 13;
26 ok(defined(&Foo::these), "Foo method these() created");
27 my $foo = new Foo;
28 $foo->these(1);
29 ok($foo->these(), "Setter for these() works");
30 ok($foo->these_isset(), "these_isset() is correct");
31 $foo->these_reset();
32 ok(!$foo->these_isset(), "these_reset() affects these_isset() properly");
33 ok(!defined($foo->these()), "these_reset() also delete value properly");
34 $foo->these(1);
35 ok($foo->these_isset(), "these_isset() works after setting");
36 is($foo->methods(), 3, "Default option worked");
38 use CXGN::DB::Connection { verbose => 0 };
39 my $dbh = CXGN::DB::Connection->new();
40 my $grub = new Foo;
41 eval {
42 $foo->dbh($grub);
44 diag("Expected error: ". $@);
45 ok($@, "Setting dbh() to non-CXGN::DB::Connection type failed, as it should");
47 eval {
48 $foo->dbh($dbh);
50 ok(!$@, "Setting dbh to CXGN::DB::Connection object successful");
52 ok(defined(&Foo::prepare), "Method prepare() exists on Foo");
54 my $sql = "SELECT COUNT(*) FROM sgn_people.sp_person";
55 diag("Preparing SQL: ". $sql);
56 my $sth = $foo->prepare($sql);
57 $sth->execute();
58 my ($count) = $sth->fetchrow_array();
60 ok($count, "Foo correctly forwards prepare() to its dbh() and gets a result: $count");
62 $foo->static_var(3);
63 is(Foo->static_var(), 3, "Static scalar set, tested on package");
64 my $foo2 = new Foo;
65 is($foo2->static_var(), 3, "Static scalar set, tested on different instance");