[Jifty-commit] r1559 - Jifty-DBI/trunk/lib/Jifty/DBI
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jul 13 16:20:46 EDT 2006
Author: audreyt
Date: Thu Jul 13 16:20:46 2006
New Revision: 1559
Modified:
Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
Log:
* Jifty::DBI::Schema: Lift the restriction to use another ::Schema
package on the record model class; you can now directly write:
package Wifty::Model::Page;
use Jifty::DBI::Schema;
schema {
# ... your columns here ...
};
because &schema will unregister all symbols exported by Jifty::DBI::Schema
after it runs the column initialization code. Backward compatibility is
preserved -- as long as you don't name your record model "Schema"...
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Schema.pm Thu Jul 13 16:20:46 2006
@@ -9,8 +9,12 @@
=head1 SYNOPSIS
-package Wifty::Model::Page::Schema;
-use Jifty::DBI::Schema;
+ package Wifty::Model::Page;
+ use Jifty::DBI::Schema;
+
+ schema {
+ # ... your columns here ...
+ };
=cut
@@ -40,14 +44,38 @@
use Carp qw/croak carp/;
use Exporter::Lite;
our @EXPORT
- = qw(column type default literal validator immutable unreadable length distinct mandatory not_null sort_order valid_values label hints render_as since input_filters output_filters filters virtual is by are on);
+ = qw(column type default literal validator immutable unreadable length distinct mandatory not_null sort_order valid_values label hints render_as since input_filters output_filters filters virtual is by are on schema);
our $SCHEMA;
our $SORT_ORDERS = {};
=head1 FUNCTIONS
-All these functions are exported.
+All these functions are exported. However, if you use the C<schema> helper function,
+they will be unimported at the end of the block passed to C<schema>.
+
+=head2 schema
+
+Takes a block with schema declarations. Unimports all helper functions after
+executing the code block.
+
+=cut
+
+sub schema (&) {
+ my $code = shift;
+
+ # First we run the code as usual.
+ my $rv = $code->();
+
+ # Unimport all our symbols from the calling package.
+ my $from = (caller)[0];
+ foreach my $sym (@EXPORT) {
+ no strict 'refs';
+ undef *{"$from\::$sym"};
+ }
+
+ return $rv;
+}
=head2 column
More information about the Jifty-commit
mailing list