Class-DBI-Plugin-DeepAbstractSearchPager
view release on metacpan or search on metacpan
lib/Class/DBI/Plugin/DeepAbstractSearchPager.pm view on Meta::CPAN
=over 4
=item $class
A class with a C<make_limit> method.
=item $name
Name of a class in the C<Class::DBI::Plugin::Pager::> namespace, which has a
C<make_limit> method.
=item $coderef
Will be called as a method on the pager object, so receives the pager as its
argument.
=item (no args)
Called without args, will default to C<LimitOffset>, which causes
L<Class::DBI::Plugin::Pager::LimitOffset|Class::DBI::Plugin::Pager::LimitOffset>
to be used.
=back
=cut
sub set_syntax {
my ( $proto, $syntax ) = @_;
# pick up default from subclass, or load from LimitOffset
$syntax ||= $proto->can( 'make_limit' );
$syntax ||= 'LimitOffset';
if ( ref( $syntax ) eq 'CODE' )
{
$proto->_syntax( $syntax );
return $syntax;
}
my $format_class = $syntax =~ '::' ? $syntax : "Class::DBI::Plugin::Pager::$syntax";
$format_class->require || croak "error loading $format_class: $UNIVERSAL::require::ERROR";
my $formatter = $format_class->can( 'make_limit' ) || croak "no make_limit method in $format_class";
$proto->_syntax( $formatter );
return $formatter;
}
=item auto_set_syntax
This is called automatically when you call C<pager>, and attempts to set the
syntax automatically.
If you are using a subclass of the pager, this method will not be called.
Will C<die> if using Oracle or DB2, since there is no simple syntax for limiting
the results set. DB2 has a C<FETCH> keyword, but that seems to apply to a
cursor and I don't know if there is a cursor available to the pager. There
should probably be others to add to the unsupported list.
Supports the following drivers:
DRIVER CDBI::P::Pager subclass
my %supported = ( pg => 'LimitOffset',
mysql => 'LimitOffset', # older versions need LimitXY
sqlite => 'LimitOffset', # or LimitYX
interbase => 'RowsTo',
firebird => 'RowsTo',
);
Older versions of MySQL should use the LimitXY syntax. You'll need to set it
manually, either by C<use CDBI::P::Pager::LimitXY>, or by passing
C<syntax =E<gt> 'LimitXY'> to a method call, or call C<set_syntax> directly.
Any driver not in the supported or unsupported lists defaults to LimitOffset.
Any additions to the supported and unsupported lists gratefully received.
=cut
sub auto_set_syntax {
my ( $self ) = @_;
# not an exhaustive list
my %not_supported = ( oracle => 'Oracle',
db2 => 'DB2',
);
# additions welcome
my %supported = ( pg => 'LimitOffset',
mysql => 'LimitOffset', # older versions need LimitXY
sqlite => 'LimitOffset', # or LimitYX
interbase => 'RowsTo',
firebird => 'RowsTo',
);
my $cdbi = $self->_cdbi_app;
my $driver = lc( $cdbi->__driver );
die __PACKAGE__ . " can't build limit clauses for $not_supported{ $driver }"
if $not_supported{ $driver };
$self->set_syntax( $supported{ $driver } || 'LimitOffset' );
}
1;
__END__
#=for notes
#
#Would this work?
#
#with $limit and $offset defined.
#
#my $last = $limit + $offset
#
( run in 2.203 seconds using v1.01-cache-2.11-cpan-f56aa216473 )