From 59a8a7b0fb76a6488fe51408d8e82f54b10b5323 Mon Sep 17 00:00:00 2001 From: Sergiy Zuban Date: Mon, 23 Jun 2014 15:25:26 -0500 Subject: [PATCH 1/2] remove schema prefix in define_ methods as well --- lib/DBIx/DataModel/Meta/Schema.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/DBIx/DataModel/Meta/Schema.pm b/lib/DBIx/DataModel/Meta/Schema.pm index e291c63..f1c087f 100644 --- a/lib/DBIx/DataModel/Meta/Schema.pm +++ b/lib/DBIx/DataModel/Meta/Schema.pm @@ -242,7 +242,12 @@ foreach my $kind (qw/table association type/) { # store into our registry (except paths because they are accessed through # tables or through associations) - $self->{$kind}{$meta_obj->{name}} = $meta_obj + + my $name = $meta_obj->{name}; + # remove schema prefix, if any + $name =~ s/^$self->{class}:://; + + $self->{$kind}{$name} = $meta_obj unless $kind eq 'path'; return $self; From dd5cfdbcd332550433d625cdf1d8dbbdf7a0b579 Mon Sep 17 00:00:00 2001 From: Sergiy Zuban Date: Wed, 2 Jul 2014 13:08:41 -0500 Subject: [PATCH 2/2] tests for table declarations using short/full names --- t/v2_define_class.t | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/t/v2_define_class.t b/t/v2_define_class.t index 3c5c47b..584db94 100644 --- a/t/v2_define_class.t +++ b/t/v2_define_class.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 10; if (1 == 0) { # the line below artificially populates DBIx::DataModel::Schema namespace @@ -12,11 +12,27 @@ if (1 == 0) { require DBIx::DataModel; -DBIx::DataModel->Schema('HR') - ->Table(Employee => T_Employee => qw/emp_id/) - ->Table(Department => T_Department => qw/dpt_id/) - ->Table(Activity => T_Activity => qw/act_id/); - +my $schema = DBIx::DataModel->Schema('HR'); +$schema->Table(Employee => T_Employee => qw/emp_id/) + ->Table(Department => T_Department => qw/dpt_id/) + ->Table(Activity => T_Activity => qw/act_id/); ok(scalar(keys %{HR::}), "class HR is defined"); +# declaraton using short name +$schema->Table( 'Bar' => T_Bar => qw/id/); +ok(scalar(keys %{HR::Bar::}), "class HR::Bar is defined"); +ok( $schema->table( 'Bar' ), 'Bar accessible via short name' ); +ok( $schema->table( 'HR::Bar' ), 'HR::Bar accessible via full name' ); + +# declaraton using full name (within schema) +$schema->Table( 'HR::Foo' => T_Foo => qw/id/); +ok(scalar(keys %{HR::Foo::}), "class HR::Foo is defined"); +ok( $schema->table( 'Foo' ), 'Foo accessible via short name' ); +ok( $schema->table( 'HR::Foo' ), 'HR::Foo accessible via full name' ); + +# declaraton using full name (outside of schema) +$schema->Table( 'Space::Empty' => T_Empty => qw/id/); +ok(scalar(keys %{Space::Empty::}), "class Space::Empty is defined"); +ok( !$schema->table( 'Empty' ), 'Empty is not accessible via short name' ); +ok( $schema->table( 'Space::Empty' ), 'Space::Empty accessible via full name only' );