r33414 - in /branches/upstream/libclass-dbi-loader-relationship-perl: ./ current/ current/Changes current/MANIFEST current/META.yml current/Makefile.PL current/README current/Relationship.pm current/test.pl
ryan52-guest at users.alioth.debian.org
ryan52-guest at users.alioth.debian.org
Thu Apr 16 03:36:07 UTC 2009
Author: ryan52-guest
Date: Thu Apr 16 03:36:03 2009
New Revision: 33414
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=33414
Log:
[svn-inject] Installing original source of libclass-dbi-loader-relationship-perl
Added:
branches/upstream/libclass-dbi-loader-relationship-perl/
branches/upstream/libclass-dbi-loader-relationship-perl/current/
branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes (with props)
branches/upstream/libclass-dbi-loader-relationship-perl/current/MANIFEST
branches/upstream/libclass-dbi-loader-relationship-perl/current/META.yml
branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL (with props)
branches/upstream/libclass-dbi-loader-relationship-perl/current/README (with props)
branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm (with props)
branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl (with props)
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes Thu Apr 16 03:36:03 2009
@@ -1,0 +1,16 @@
+Revision history for Perl extension Class::DBI::Loader::Relationship.
+
+1.3 Tue Nov 9 09:00:00 GMT 2005
+ - add support for mapper alias (chunzi)
+
+See
+http://cvs.simon-cozens.org/viewcvs.cgi/Class-DBI-Loader-Relationship/
+for full log
+
+1.1 Tue Jan 6 21:54:47 GMT 2004
+ - Make reverse relationship has_a, not has_many.
+
+0.01 Wed Dec 31 16:44:42 2003
+ - original version; created by h2xs 1.21 with options
+ -AX -n Class::DBI::Loader::Relationship
+
Propchange: branches/upstream/libclass-dbi-loader-relationship-perl/current/Changes
------------------------------------------------------------------------------
svn:executable =
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/MANIFEST?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/MANIFEST (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/MANIFEST Thu Apr 16 03:36:03 2009
@@ -1,0 +1,7 @@
+Changes
+Makefile.PL
+MANIFEST
+README
+Relationship.pm
+test.pl
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/META.yml?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/META.yml (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/META.yml Thu Apr 16 03:36:03 2009
@@ -1,0 +1,12 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Class-DBI-Loader-Relationship
+version: 1.3
+version_from: Relationship.pm
+installdirs: site
+requires:
+ Class::DBI::Loader: 0
+ Lingua::EN::Inflect::Number: 1
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL Thu Apr 16 03:36:03 2009
@@ -1,0 +1,11 @@
+use ExtUtils::MakeMaker;
+# See lib/ExtUtils/MakeMaker.pm for details of how to influence
+# the contents of the Makefile that is written.
+WriteMakefile(
+ 'NAME' => 'Class::DBI::Loader::Relationship',
+ 'VERSION_FROM' => 'Relationship.pm', # finds $VERSION
+ 'PREREQ_PM' => {
+ Class::DBI::Loader => 0,
+ Lingua::EN::Inflect::Number => 1,
+ }, # e.g., Module::Name => 1.1
+);
Propchange: branches/upstream/libclass-dbi-loader-relationship-perl/current/Makefile.PL
------------------------------------------------------------------------------
svn:executable =
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/README?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/README (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/README Thu Apr 16 03:36:03 2009
@@ -1,0 +1,35 @@
+Class/DBI/Loader/Relationship version 0.01
+==========================================
+
+The README is used to introduce the module and provide instructions on
+how to install the module, any machine dependencies it may have (for
+example C compilers and installed libraries) and any other information
+that should be provided before the module is installed.
+
+A README file is required for CPAN modules since CPAN extracts the
+README file from a module distribution so that people browsing the
+archive can use it get an idea of the modules uses. It is usually a
+good idea to provide version information here so that people can
+decide whether fixes for the module are worth downloading.
+
+INSTALLATION
+
+To install this module type the following:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+ blah blah blah
+
+COPYRIGHT AND LICENCE
+
+Put the correct copyright and licence information here.
+
+Copyright (C) 2003 A. U. Thor blah blah blah
+
Propchange: branches/upstream/libclass-dbi-loader-relationship-perl/current/README
------------------------------------------------------------------------------
svn:executable =
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm Thu Apr 16 03:36:03 2009
@@ -1,0 +1,126 @@
+package Class::DBI::Loader::Relationship;
+use 5.006;
+use strict;
+use warnings;
+our $VERSION = '1.3';
+our $DEBUG = 0;
+
+1;
+
+=head1 NAME
+
+Class::DBI::Loader::Relationship - Easier relationship specification in CDBI::Loader
+
+=head1 SYNOPSIS
+
+ use Class::DBI::Loader::Relationship;
+
+ my $loader = Class::DBI::Loader->new( dsn => "mysql:beerdb",
+ namespace => "BeerDB");
+
+Now instead of saying
+
+ BeerDB::Brewery->has_many(beers => "BeerDB::Beer");
+ BeerDB::Beer->has_a(brewery => "BeerDB::Brewery");
+
+ BeerDB::Handpump->has_a(beer => "BeerDB::Beer");
+ BeerDB::Handpump->has_a(pub => "BeerDB::Pub");
+ BeerDB::Pub->has_many(beers => [ BeerDB::Handpump => 'beer' ]);
+ BeerDB::Beer->has_many(pubs => [ BeerDB::Handpump => 'pub' ]);
+
+
+Just say
+
+ $loader->relationship( "a brewery produces beers" );
+ $loader->relationship( "a pub has beers on handpumps" );
+
+And something like ( upgraded in v1.3 )
+
+ MyApp::Page->has_a( author => 'MyApp::User' );
+ MyApp::Page->has_many( revisions => 'MyApp::PageRevision' );
+
+Just say
+
+ $loader->relationship( "a page has an user as author" );
+ $loader->relationship( "a page has many page_revisions as revisions" );
+
+=head1 DESCRIPTION
+
+This module acts as a mix-in, adding the C<relationship> method to
+C<Class::DBI::Loader>. Since C<Class::DBI::Loader> knows how to map
+between table names and class names, there ought to be no need to
+replicate the names.
+
+In addition, it is common (but not universal) to want reverse relationships
+defined for has-many relationships, and for has-a relationships to be
+defined for the linkages surrounding a many-to-many table.
+
+The aim of C<CDBIL::Relationship> is to simplify the declaration of
+common database relationships by providing both of these features.
+
+The C<relationship> takes a string. It recognises table names (singular
+or plural, for convenience) and extracts them from the "sentence".
+
+=cut
+
+package Class::DBI::Loader::Generic;
+use Lingua::EN::Inflect::Number qw(PL to_PL to_S);
+use Carp;
+
+sub relationship {
+ my $self = shift;
+ my $text = shift;
+ my %tables = map { $_ => $_, PL($_) => $_ } $self->tables;
+ my $table_re = join "|", map quotemeta,
+ sort { length $b <=> length $a } keys %tables;
+ croak "Couldn't understand the first object you were talking about"
+ unless $text =~ s/^((an?|the)\s+)?($table_re)\s*//i;
+ my $from = $tables{$3};
+ my $from_c = $self->find_class($from);
+ $text =~ s/^(might\s+)?\w+(\s+an?)?\s+//i;
+ my $method = "has_many";
+ $method = "has_a" if $2;
+ $method = "might_have" if $1;
+
+ croak "Couldn't understand the second object you were talking about"
+ unless $text =~ s/.*?($table_re)\b//i;
+ my $to = $tables{$1};
+ my $to_c = $self->find_class($to);
+ my $mapper = $method eq "has_many" ? to_PL($to) : to_S($to);
+
+ $mapper = $1 if $text =~ s/\s+as\s+(\w+)$//i;
+
+ if ($text =~ /($table_re)/i) {
+ my $via = $tables{$1}; my $via_c = $self->find_class($via);
+ return "$via_c->has_a(".to_S($from)." => $from_c)\n".
+ "$via_c->has_a(".to_S($to)." => $to_c)\n".
+ "$from_c->$method($mapper => [ $via_c => ".to_S($to)." ])\n".
+ "$to_c->has_many(".to_PL($from)." => [ $via_c => ".to_S($from)." ])\n"
+ if $DEBUG;
+
+ $via_c->has_a(to_S($from) => $from_c);
+ $via_c->has_a(to_S($to) => $to_c);
+ $from_c->$method($mapper => [ $via_c => to_S($to) ]);
+ $to_c->has_many(to_PL($from) => [ $via_c => to_S($from) ]);
+ return;
+ }
+ return "$from_c->$method($mapper => $to_c);\n".
+ ($method ne "has_a" && "$to_c->has_a(".to_S($from)." => $from_c);\n")
+ if $DEBUG;
+ $from_c->$method($mapper => $to_c);
+ $to_c->has_a(to_S($from) => $from_c) unless $method eq "has_a";
+}
+
+1;
+
+=head1 AUTHOR
+
+Simon Cozens, C<simon at cpan.org>
+
+Chunzi, C<chunzi at perlchina.org>
+
+=head1 SEE ALSO
+
+L<Class::DBI::Loader>.
+
+=cut
Propchange: branches/upstream/libclass-dbi-loader-relationship-perl/current/Relationship.pm
------------------------------------------------------------------------------
svn:executable =
Added: branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl?rev=33414&op=file
==============================================================================
--- branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl (added)
+++ branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl Thu Apr 16 03:36:03 2009
@@ -1,0 +1,36 @@
+use Test::More 'no_plan';
+use_ok("Class::DBI::Loader::Relationship");
+use Class::DBI::Loader::Generic;
+
+my $fake = bless {
+ CLASSES => { reverse(
+ BeerDB::Brewery => "brewery",
+ BeerDB::Beer => "beer",
+ BeerDB::Handpump => "handpump",
+ BeerDB::Pub => "pub"
+ )
+ }
+}, 'Class::DBI::Loader::Generic';
+
+$Class::DBI::Loader::Relationship::DEBUG = 1;
+
+my $crib1 = <<EOF;
+BeerDB::Brewery->has_many(beers => BeerDB::Beer);
+BeerDB::Beer->has_a(brewery => BeerDB::Brewery);
+EOF
+sub test { my($text, $crib) = @_; is($fake->relationship($text), $crib, $text)}
+
+test("a brewery produces beers", $crib1);
+test("breweries produce beer", $crib1);
+test("a brewery has a beer", "BeerDB::Brewery->has_a(beer => BeerDB::Beer);\n");
+
+my $crib2 = <<EOF;
+BeerDB::Handpump->has_a(pub => BeerDB::Pub)
+BeerDB::Handpump->has_a(beer => BeerDB::Beer)
+BeerDB::Pub->has_many(beers => [ BeerDB::Handpump => beer ])
+BeerDB::Beer->has_many(pubs => [ BeerDB::Handpump => pub ])
+EOF
+
+test("pubs have beer on handpumps", $crib2);
+
+test("a brewery has a beer as another_beer", "BeerDB::Brewery->has_a(another_beer => BeerDB::Beer);\n");
Propchange: branches/upstream/libclass-dbi-loader-relationship-perl/current/test.pl
------------------------------------------------------------------------------
svn:executable =
More information about the Pkg-perl-cvs-commits
mailing list