#!/usr/bin/perl use 5.010_000; use strict; use warnings; use utf8; use FindBin; use lib "$FindBin::Bin/../lib"; use MyApp::ConcreteTableInheritance::Schema; my $schema = MyApp::ConcreteTableInheritance::Schema->connect( 'dbi:SQLite:dbname=:memory:', ); $schema->deploy; my $txn_guard = $schema->txn_scope_guard; say 'Footballer:'; my $footballer_rs = $schema->resultset('Footballer'); my $new_footballer = $footballer_rs->create({ name => 'Foo Bar the Kicker', club => 'Baz F.C.', }); $new_footballer->salute; $new_footballer->kick; say q(); say 'Cricketer:'; my $cricketer_rs = $schema->resultset('Cricketer'); my $new_cricketer = $cricketer_rs->create({ name => 'Foo Bar the Cricketer', batting_average => 0.345, }); $new_cricketer->salute; $new_cricketer->bat; say q(); say 'Bowler:'; my $bowler_rs = $schema->resultset('Bowler'); my $new_bowler = $bowler_rs->create({ name => 'Foo Bar the Bowler', batting_average => 0.234, bowling_average => 0.123, }); $new_bowler->salute; $new_bowler->bat; $new_bowler->bowl; say q(); $txn_guard->commit; say 'Footballers:'; my $all_footballers_rs = $footballer_rs->search({}); while (my $footballer = $all_footballers_rs->next) { printf( "%s,%s,%s\n", $footballer->id, $footballer->name, $footballer->club, ); } say q(); say 'Cricketers:'; my $all_cricketers_rs = $cricketer_rs->search({}); while (my $cricketer = $all_cricketers_rs->next) { printf( "%s,%s,%0.3f\n", $cricketer->id, $cricketer->name, $cricketer->batting_average, ); } say q(); say 'Bowlers:'; my $all_bowlers_rs = $bowler_rs->search({}); while (my $bowler = $all_bowlers_rs->next) { printf( "%s,%s,%0.3f,%0.3f\n", $bowler->id, $bowler->name, $bowler->batting_average, $bowler->bowling_average, ); } say q(); exit; __END__ =pod =encoding utf-8 =head1 NAME concrete_table_inheritance - An implementation of the Concrete Table Inheritance pattern =head1 SYNOPSIS % perl concrete_table_inheritance.pl Footballer: Hello, my name is Foo Bar the Kicker. Foo Bar the Kicker (Baz F.C.) kicks a ball! Cricketer: Hello, my name is Foo Bar the Cricketer. Foo Bar the Cricketer (ave.: 0.345) bats a ball! Bowler: Hello, my name is Foo Bar the Bowler. Foo Bar the Bowler (ave.: 0.234) bats a ball! Foo Bar the Bowler (ave.: 0.123) bowls a ball! Footballers: D1187178-97B2-1014-A58F-D4AC52A7D995,Foo Bar the Kicker,Baz F.C. Cricketers: D4E37767-97B2-1014-B8E9-EC12DD115C94,Foo Bar the Cricketer,0.345 Bowlers: D520973D-97B2-1014-B909-CBDD2129B220,Foo Bar the Bowler,0.234,0.123 =head1 DESCRIPTION blah blah blah =head2 Schema CREATE TABLE footballers ( id CHAR(36) NOT NULL, name VARCHAR(32) NOT NULL, club VARCHAR(32) NOT NULL, PRIMARY KEY (id) ); CREATE TABLE cricketers ( id char(36) NOT NULL, name varchar(32) NOT NULL, batting_average float NOT NULL, PRIMARY KEY (id) ); CREATE TABLE bowlers ( id CHAR(36) NOT NULL, name VARCHAR(32) NOT NULL, batting_average float NOT NULL, bowling_average float NOT NULL, PRIMARY KEY (id) ); CREATE UNIQUE INDEX __PLACEHOLDER___name ON bowlers (name); -- sucks CREATE UNIQUE INDEX __PLACEHOLDER___name02 ON cricketers (name); -- sucks CREATE UNIQUE INDEX __PLACEHOLDER___name03 ON footballers (name); -- sucks CREATE UNIQUE INDEX bowlers_name ON bowlers (name); CREATE UNIQUE INDEX cricketers_name ON bowlers (name); CREATE UNIQUE INDEX cricketers_name02 ON cricketers (name); -- sucks CREATE UNIQUE INDEX footballers_name ON footballers (name); =head1 TO DO =over 4 =item * L 0.10 cannot apply type constraints at instanciation. =back =head1 SEE ALSO =over 4 =item * L =item * L =back =head1 AUTHOR =over 4 =item MORIYA Masaki, alias Gardejo C<< >>, L =back =head1 COPYRIGHT AND LICENSE Copyright (c) 2010 MORIYA Masaki, alias Gardejo. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L and L. The full text of the license can be found in the F file included with this distribution. =cut