| 1 | package Jifty::DBI::HasFilters; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 36 | ▶ | use base qw/Class::Accessor::Fast/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 36 | __PACKAGE__->mk_accessors(qw/ input_filters output_filters filters /); | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Jifty::DBI::HasFilters - abstract class for objects that has filters | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | my $record = Jifty::DBI::Record->new(...); | ||||||||||||||||||||||||||||
| 16 | $record->input_filters( 'Jifty::DBI::Filter::Truncate', | ||||||||||||||||||||||||||||
| 17 | 'Jifty::DBI::Filter::utf8' | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | my @filters = $record->output_filters; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | This abstract class provide generic interface for setting and getting | ||||||||||||||||||||||||||||
| 24 | input and output data filters for L<Jifty::DBI> objects. | ||||||||||||||||||||||||||||
| 25 | You shouldn't use it directly, but L<Jifty::DBI::Handle>, L<Jifty::DBI::Record> | ||||||||||||||||||||||||||||
| 26 | and L<Jifty::DBI::Column> classes inherit this interface. | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 METHODS | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head2 input_filters | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Returns array of the input filters, if arguments list is not empty | ||||||||||||||||||||||||||||
| 34 | then set input filter. | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub input_filters { | ||||||||||||||||||||||||||||
| 39 | 2537 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
input_filters: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 2537 | ▶ | if (@_) { # setting | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 485 | ▶ | my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 485 | $self->{input_filters} = \@values; | |||||||||||||||||||||||||||
| 43 | 485 | return @values; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2052 | ▶ | return @{ $self->{input_filters} || [] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =head2 output_filters | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | Deals similar with list of output filters, but unless | ||||||||||||||||||||||||||||
| 52 | you defined own list returns reversed list of the input | ||||||||||||||||||||||||||||
| 53 | filters. In common situation you don't need to define | ||||||||||||||||||||||||||||
| 54 | own list of output filters, but use this method to get | ||||||||||||||||||||||||||||
| 55 | default list based on the input list. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | sub output_filters { | ||||||||||||||||||||||||||||
| 60 | 937 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
output_filters: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 937 | ▶ | if (@_) { # setting | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 96 | ▶ | my @values = map { UNIVERSAL::isa( $_, 'ARRAY' ) ? @$_ : $_ } @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 96 | $self->{output_filters} = \@values; | |||||||||||||||||||||||||||
| 64 | 96 | return @values; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 841 | my $values = $self->{output_filters}; | |||||||||||||||||||||||||||
| 68 | 841 | ▶ | return @$values if $values && @$values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$values and @$values
MC/DC0%0/2
$values and @$values
$values
@$values
Truth table66%2/3
A and B
A= $valuesB= @$values
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 841 | return reverse $self->input_filters; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head2 filters FILTERS | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | Sets the input and output filters at the same time. Returns a hash, | ||||||||||||||||||||||||||||
| 76 | with keys C<input> and C<output>, whose values are array references to | ||||||||||||||||||||||||||||
| 77 | the respective lists. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub filters { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
filters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | return { | ||||||||||||||||||||||||||||
| 84 | 0 | output => $self->output_filters(@_), | |||||||||||||||||||||||||||
| 85 | input => $self->input_filters(@_) | ||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | L<Jifty::DBI::Filter> | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 36 | 1; | |||||||||||||||||||||||||||