Aniki::Filter::Declare - DSL for declaring actions on sometimes
package MyApp::DB::Filter; use strict; use warnings; use Aniki::Filter::Declare; use Scalar::Util qw/blessed/; use Time::Moment; use Data::GUID::URLSafe; # apply callback to row before insert trigger insert => sub { my ($row, $next) = @_; $row->{created_at} = Time::Moment->now; return $next->($row); }; # define trigger/inflate/deflate filters in table context. table author => sub { trigger insert => sub { my ($row, $next) = @_; $row->{guid} = Data::GUID->new->as_base64_urlsafe; return $next->($row); }; inflate name => sub { my $name = shift; return uc $name; }; deflate name => sub { my $name = shift; return lc $name; }; }; # define inflate/deflate filters in global context. (apply to all tables) inflate qr/_at$/ => sub { my $datetime = shift; return Time::Moment->from_string($datetime.'Z', lenient => 1); }; deflate qr/_at$/ => sub { my $datetime = shift; return $datetime->at_utc->strftime('%F %T') if blessed $datetime and $datetime->isa('Time::Moment'); return $datetime; };
table
inflate
deflate
trigger
perl
Copyright (C) karupanerura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
karupanerura <karupa@cpan.org>
To install Aniki, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Aniki
CPAN shell
perl -MCPAN -e shell install Aniki
For more information on module installation, please visit the detailed CPAN module installation guide.