| 1 | { | ||
| 2 | package Class::DBI::FormBuilder::DBI::Test; | ||
| 3 | 30 | ▶ | use base 'Class::DBI'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 30 | ▶ | use Class::DBI::FormBuilder PrettyPrint => 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | # use the db set up in 01.create.t | ||
| 6 | 30 | Class::DBI::FormBuilder::DBI::Test->set_db("Main", "dbi:SQLite2:dbname=test.db"); | |
| 7 | } | ||
| 8 | |||
| 9 | { # might_have | ||
| 10 | 30 | package Job; | |
| 11 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 30 | Job->table( 'job' ); | |
| 13 | 30 | Job->columns( All => qw/id person jobtitle employer salary/ ); | |
| 14 | 30 | Job->columns( Stringify => qw/jobtitle/ ); | |
| 15 | 30 | Job->has_a( person => 'Person' ); | |
| 16 | } | ||
| 17 | |||
| 18 | { # has_a | ||
| 19 | 30 | package Town; | |
| 20 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | #Town->form_builder_defaults( { smartness => 3 } ); | ||
| 22 | 30 | Town->table("town"); | |
| 23 | 30 | Town->columns(All => qw/id name pop lat long country/); | |
| 24 | 30 | Town->columns(Stringify => qw/name/); | |
| 25 | } | ||
| 26 | |||
| 27 | { # has_many | ||
| 28 | # this one must be declared before Person, because Person will | ||
| 29 | # examine the has_a in Toy when setting up its has_many toys. | ||
| 30 | 30 | package CDBIFB::Toy; | |
| 31 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 32 | 30 | CDBIFB::Toy->table('toy'); | |
| 33 | 30 | CDBIFB::Toy->columns( All => qw/id person name descr/ ); | |
| 34 | 30 | CDBIFB::Toy->columns( Stringify => qw/name/ ); | |
| 35 | 30 | CDBIFB::Toy->has_a( person => 'Person' ); | |
| 36 | } | ||
| 37 | |||
| 38 | { | ||
| 39 | 30 | package Person; | |
| 40 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 41 | #Person->form_builder_defaults( { smartness => 3 } ); | ||
| 42 | 30 | Person->table("person"); | |
| 43 | 30 | Person->columns(All => qw/id name town street/); | |
| 44 | 30 | Person->columns(Stringify => qw/name/); | |
| 45 | 30 | Person->has_a( town => 'Town' ); | |
| 46 | 30 | Person->has_many( toys => 'CDBIFB::Toy' ); | |
| 47 | 30 | Person->might_have( job => Job => qw/jobtitle employer salary/ ); | |
| 48 | } | ||
| 49 | |||
| 50 | { | ||
| 51 | 30 | package Wackypk; | |
| 52 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 53 | 30 | Wackypk->table("wackypk"); | |
| 54 | # wooble is the pk | ||
| 55 | 30 | Wackypk->columns(All => qw/flooble wooble flump poo/); | |
| 56 | 30 | Wackypk->columns(Primary => 'wooble'); # or put wooble 1st in the list above | |
| 57 | } | ||
| 58 | |||
| 59 | { | ||
| 60 | 30 | package CDBIFB::Alias; | |
| 61 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 62 | 30 | CDBIFB::Alias->table( 'alias' ); | |
| 63 | 30 | CDBIFB::Alias->columns(All => qw/id colour fruit town/); | |
| 64 | 30 | CDBIFB::Alias->columns(Stringify => 'fruit' ); | |
| 65 | |||
| 66 | 30 | CDBIFB::Alias->has_a( town => 'Town' ); | |
| 67 | |||
| 68 | 30 | CDBIFB::Alias->has_many( alias_has_many => 'AliasHasMany' ); | |
| 69 | 30 | CDBIFB::Alias->might_have( job => Job => qw/jobtitle employer salary/ ); | |
| 70 | |||
| 71 | |||
| 72 | 0 | ▶ | sub accessor_name { "get_$_[1]" } # deprecated somewhere |
|
Subroutine
accessor_name: not called CC=1 SCAR=6.9
| |||
| 73 | 0 | ▶ | sub mutator_name { "set_$_[1]" } # deprecated somewhere |
|
Subroutine
mutator_name: not called CC=1 SCAR=6.9
| |||
| 74 | 150 | ▶ | sub accessor_name_for { "get_$_[1]" } |
|
Subroutine
accessor_name_for: called CC=1 SCAR=0.0
| |||
| 75 | 150 | ▶ | sub mutator_name_for { "set_$_[1]" } |
|
Subroutine
mutator_name_for: called CC=1 SCAR=0.0
| |||
| 76 | } | ||
| 77 | |||
| 78 | { | ||
| 79 | 30 | package AliasHasMany; | |
| 80 | 30 | ▶ | use base 'Class::DBI::FormBuilder::DBI::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 81 | 30 | AliasHasMany->table( 'alias_has_many' ); | |
| 82 | 30 | AliasHasMany->columns( All => qw/id alias foo/ ); | |
| 83 | 30 | AliasHasMany->columns( Stringify => 'foo' ); | |
| 84 | 30 | AliasHasMany->has_a( alias => 'CDBIFB::Alias' ); | |
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | 30 | 1; | |