Jifty-DBI
view release on metacpan or search on metacpan
lib/Jifty/DBI/Schema.pm view on Meta::CPAN
use Scalar::Defer;
use base qw(Class::Data::Inheritable);
__PACKAGE__->mk_classdata('TYPES' => {});
use Object::Declare (
mapping => {
column => sub { Jifty::DBI::Column->new({@_}) } ,
},
aliases => {
default_value => 'default',
available => 'available_values',
valid => 'valid_values',
render => 'render_as',
order => 'sort_order',
filters => 'input_filters',
},
copula => {
is => sub { return @_ if $#_;
my $typehandler = __PACKAGE__->TYPES->{$_[0]};
# XXX: when we have a type name
# convention, give a warning when it
# looks like a type name but not found
return ($_[0] => 1) unless $typehandler;
return $typehandler->();
},
are => '',
as => '',
ajax => 'ajax_',
refers_to => sub { refers_to => @_ },
references => sub { refers_to => @_ },
},
);
use Class::Data::Inheritable;
use UNIVERSAL::require ();
our @EXPORT = qw( defer lazy column schema by render_as since till literal);
sub by ($) { @_ }
sub render_as ($) { render as @_ }
sub since ($) { since is @_ }
sub till ($) { till is @_ }
sub literal($) {
my $value = shift;
return \$value;
}
our $SCHEMA;
our $SORT_ORDERS = {};
use Exporter::Lite ();
# TODO - This "sub import" is strictly here to catch the deprecated "length is 40".
# Once the deprecation cycle is over we should take the SIGDIE swapping away
my $old_sig_die;
sub import {
no warnings qw( uninitialized numeric );
$old_sig_die ||= $SIG{__DIE__};
$SIG{__DIE__} = \&filter_die unless $SIG{__DIE__} and $SIG{__DIE__} == \&filter_die;
strict->import;
warnings->import;
goto &Exporter::Lite::import;
}
=head2 filter_die
=cut
sub filter_die {
# Calling it by hand means we restore the old sighandler.
$SIG{__DIE__} = $old_sig_die;
if ($_[0] =~ /near "is (\d+)"/) {
carp @_, << ".";
*********************************************************
Due to an incompatible API change, the "length" field in
Jifty::DBI columns has been renamed to "max_length":
column foo =>
length is $1; # NOT VALID
Please write this instead:
column foo =>
max_length is $1 # VALID
Sorry for the inconvenience.
**********************************************************
.
exit 1;
}
elsif ($_[0] =~ /Undefined subroutine &Jifty::DBI::Schema::column|Can't locate object method "type" via package "(?:is|are)"/) {
my $from = (caller)[0];
$from =~ s/::Schema$//;
my $base = $INC{'Jifty/Record.pm'} ? "Jifty::Record" : "Jifty::DBI::Record";
no strict 'refs';
carp @_, << ".";
*********************************************************
Calling 'column' within a schema class is an error:
package $from\::Schema;
column foo => ...; # NOT VALID
Please write this instead:
package $from;
use Jifty::DBI::Schema;
use @{[(${"$from\::ISA"} || [$base])->[0] || $base]} schema {
column foo => ...; # VALID
};
Sorry for the inconvenience.
( run in 1.088 second using v1.01-cache-2.11-cpan-7fcb06a456a )