| 1 | #!/usr/bin/env perl | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | use blib; | ||
| 5 | use XAO::Utils; | ||
| 6 | use XAO::Objects; | ||
| 7 | |||
| 8 | ## | ||
| 9 | # This is not something you would normally do in your application - this | ||
| 10 | # is here purely to safely get configuration values to connect to the | ||
| 11 | # test database. | ||
| 12 | # | ||
| 13 | my %d; | ||
| 14 | if(open(F,'.config')) { | ||
| 15 | local($/); | ||
| 16 | my $t=<F>; | ||
| 17 | close(F); | ||
| 18 | eval $t; | ||
| 19 | } | ||
| 20 | die "No test configuration available (no .config)!\n" unless $d{test_dsn}; | ||
| 21 | |||
| 22 | ## | ||
| 23 | # Connecting to the database and completely erasing all the data in | ||
| 24 | # it. | ||
| 25 | # | ||
| 26 | my $odb=XAO::Objects->new(objname => 'FS::Glue', | ||
| 27 | dsn => $d{test_dsn}, | ||
| 28 | user => $d{test_user}, | ||
| 29 | password => $d{test_password}, | ||
| 30 | empty_database => 'confirm'); | ||
| 31 | |||
| 32 | $odb || die "Can't connect to the database"; | ||
| 33 | |||
| 34 | my $global=$odb->fetch('/'); | ||
| 35 | |||
| 36 | $global || die "Can't fetch Global from OS database"; | ||
| 37 | |||
| 38 | $global->add_placeholder(name => 'Customers', | ||
| 39 | type => 'list', | ||
| 40 | class => 'Data::Customer', | ||
| 41 | key => 'customer_id'); | ||
| 42 | |||
| 43 | ## | ||
| 44 | # These two lines are equal: | ||
| 45 | # | ||
| 46 | my $clist=$global->get('Customers'); | ||
| 47 | ## my $clist=$odb->fetch('/Customers'); | ||
| 48 | |||
| 49 | $clist || die "Can't get Customers from OS Global"; | ||
| 50 | |||
| 51 | my $customer=$clist->get_new(); | ||
| 52 | $customer || die "Can't create new customer"; | ||
| 53 | |||
| 54 | $customer->add_placeholder(name => 'name', | ||
| 55 | type => 'text', | ||
| 56 | maxlength=> 100); | ||
| 57 | |||
| 58 | $customer->put('name' => 'test'); | ||
| 59 | |||
| 60 | $clist->put(c1 => $customer); | ||
| 61 | $clist->put(c2 => $customer); | ||
| 62 | |||
| 63 | print "Name1: ", $customer->get('name'), "\n"; | ||
| 64 | print "Name2: ", $odb->fetch('/Customers/c1/name'), "\n"; | ||
| 65 | print "Name3: ", $global->get('Customers')->get('c2')->get('name'), "\n"; | ||
| 66 | |||
| 67 | exit(0); |