| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Mojolicious::Plugin::Vparam::Filters; | 
| 2 | 73 |  |  | 73 |  | 4275014 | use Mojo::Base -strict; | 
|  | 73 |  |  |  |  | 116127 |  | 
|  | 73 |  |  |  |  | 426 |  | 
| 3 | 73 |  |  | 73 |  | 8310 | use Mojolicious::Plugin::Vparam::Common qw(load_class); | 
|  | 73 |  |  |  |  | 180 |  | 
|  | 73 |  |  |  |  | 3690 |  | 
| 4 | 73 |  |  | 73 |  | 772 | use List::MoreUtils                     qw(any); | 
|  | 73 |  |  |  |  | 9854 |  | 
|  | 73 |  |  |  |  | 972 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | sub like($$) { | 
| 7 | 24 | 50 |  | 24 | 0 | 52 | return 'Value not defined'      unless defined $_[0]; | 
| 8 | 24 | 100 |  |  |  | 173 | return 'Wrong format'           unless $_[0] =~ $_[1]; | 
| 9 | 15 |  |  |  |  | 30 | return 0; | 
| 10 |  |  |  |  |  |  | } | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | sub in($$) { | 
| 13 | 11 |  |  | 11 | 0 | 22 | my ($str, $list) = @_; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 11 | 50 |  |  |  | 23 | die 'Not ArrayRef'              unless 'ARRAY' eq ref $list; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 11 | 100 |  |  |  | 21 | return 'Value not defined'      unless defined $str; | 
| 18 |  |  |  |  |  |  | return 'Wrong value' | 
| 19 | 10 | 50 |  | 28 |  | 50 | unless any {defined($_) && $str eq $_} @$list; | 
|  | 28 | 100 |  |  |  | 88 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 5 |  |  |  |  | 18 | return 0; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub size($$$) { | 
| 25 | 12 |  |  | 12 | 0 | 26 | my ($value, $min, $max) = @_; | 
| 26 | 12 | 100 |  |  |  | 24 | return 'Value is not defined'       unless defined $value; | 
| 27 | 10 | 100 |  |  |  | 25 | return 'Value is not set'           unless length  $value; | 
| 28 | 9 | 100 |  |  |  | 23 | return sprintf "Value should not be less than %s", $min | 
| 29 |  |  |  |  |  |  | unless $min <= length $value; | 
| 30 | 8 | 100 |  |  |  | 24 | return sprintf "Value should not be longer than %s", $max | 
| 31 |  |  |  |  |  |  | unless $max >= length $value; | 
| 32 | 6 |  |  |  |  | 15 | return 0; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub num_ge($$) { | 
| 36 | 11 |  |  | 11 | 0 | 21 | my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); | 
| 37 | 11 | 50 |  |  |  | 939 | die $e if $e; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 11 |  |  |  |  | 30 | my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); | 
| 40 | 11 | 100 |  |  |  | 27 | return $numeric if $numeric; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 7 | 100 |  |  |  | 28 | return sprintf "Value should not be greater than %s", $_[1] | 
| 43 |  |  |  |  |  |  | unless $_[0] >= $_[1]; | 
| 44 | 4 |  |  |  |  | 9 | return 0; | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub num_le($$) { | 
| 48 | 7 |  |  | 7 | 0 | 12 | my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); | 
| 49 | 7 | 50 |  |  |  | 559 | die $e if $e; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 7 |  |  |  |  | 19 | my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); | 
| 52 | 7 | 100 |  |  |  | 15 | return $numeric if $numeric; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 6 | 100 |  |  |  | 28 | return sprintf "Value should not be less than %s", $_[1] | 
| 55 |  |  |  |  |  |  | unless $_[0] <= $_[1]; | 
| 56 | 2 |  |  |  |  | 5 | return 0; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | sub num_eq($$) { | 
| 60 | 3 |  |  | 3 | 0 | 59 | my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); | 
| 61 | 3 | 50 |  |  |  | 271 | die $e if $e; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 3 |  |  |  |  | 9 | my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); | 
| 64 | 3 | 100 |  |  |  | 8 | return $numeric if $numeric; | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 2 | 100 |  |  |  | 7 | return sprintf "Value not equal"    unless $_[0] == $_[1]; | 
| 67 | 1 |  |  |  |  | 3 | return 0; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | sub num_ne($$) { | 
| 71 | 3 |  |  | 3 | 0 | 8 | my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); | 
| 72 | 3 | 50 |  |  |  | 272 | die $e if $e; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 3 |  |  |  |  | 9 | my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); | 
| 75 | 3 | 100 |  |  |  | 8 | return $numeric if $numeric; | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 2 | 100 |  |  |  | 8 | return sprintf "Value equal"        unless $_[0] != $_[1]; | 
| 78 | 1 |  |  |  |  | 2 | return 0; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub num_range($$$) { | 
| 82 | 5 |  |  | 5 | 0 | 11 | my $min = num_ge $_[0] => $_[1]; | 
| 83 | 5 | 100 |  |  |  | 11 | return $min if $min; | 
| 84 |  |  |  |  |  |  |  | 
| 85 | 3 |  |  |  |  | 8 | my $max = num_le $_[0] => $_[2]; | 
| 86 | 3 | 100 |  |  |  | 8 | return $max if $max; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  |  |  | 2 | return 0; | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | sub str_lt($$) { | 
| 92 | 1 | 50 |  | 1 | 0 | 2 | return 'Value is not defined'       unless defined $_[0]; | 
| 93 | 1 | 50 |  |  |  | 3 | return sprintf "Value should not be less than %s", $_[1] | 
| 94 |  |  |  |  |  |  | unless $_[0] lt $_[1]; | 
| 95 | 1 |  |  |  |  | 2 | return 0; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | sub str_gt($$) { | 
| 99 | 1 | 50 |  | 1 | 0 | 4 | return 'Value is not defined'       unless defined $_[0]; | 
| 100 | 1 | 50 |  |  |  | 3 | return sprintf "Value should not be greater than %s", $_[1] | 
| 101 |  |  |  |  |  |  | unless $_[0] gt $_[1]; | 
| 102 | 1 |  |  |  |  | 2 | return 0; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | sub str_le($$) { | 
| 106 | 1 | 50 |  | 1 | 0 | 4 | return 'Value is not defined'       unless defined $_[0]; | 
| 107 | 1 | 50 |  |  |  | 3 | return sprintf "Value should not be less or equal than %s", $_[1] | 
| 108 |  |  |  |  |  |  | unless $_[0] le $_[1]; | 
| 109 | 1 |  |  |  |  | 2 | return 0; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | sub str_ge($$) { | 
| 113 | 1 | 50 |  | 1 | 0 | 3 | return 'Value is not defined'       unless defined $_[0]; | 
| 114 | 1 | 50 |  |  |  | 3 | return sprintf "Value should not be greater or equal than %s", $_[1] | 
| 115 |  |  |  |  |  |  | unless $_[0] ge $_[1]; | 
| 116 | 1 |  |  |  |  | 2 | return 0; | 
| 117 |  |  |  |  |  |  | } | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | sub str_cmp($$) { | 
| 120 | 1 | 50 |  | 1 | 0 | 4 | return 'Value is not defined'       unless defined $_[0]; | 
| 121 | 1 | 50 |  |  |  | 3 | return sprintf "Value not equal"    if $_[0] cmp $_[1]; | 
| 122 | 1 |  |  |  |  | 2 | return 0; | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | sub str_eq($$) { | 
| 126 | 1 | 50 |  | 1 | 0 | 3 | return 'Value is not defined'       unless defined $_[0]; | 
| 127 | 1 | 50 |  |  |  | 3 | return sprintf "Value not equal"    unless $_[0] eq $_[1]; | 
| 128 | 1 |  |  |  |  | 2 | return 0; | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | sub str_ne($$) { | 
| 132 | 1 | 50 |  | 1 | 0 | 4 | return 'Value is not defined'       unless defined $_[0]; | 
| 133 | 1 | 50 |  |  |  | 3 | return sprintf "Value equal"        unless $_[0] ne $_[1]; | 
| 134 | 1 |  |  |  |  | 3 | return 0; | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | sub register { | 
| 138 | 75 |  |  | 75 | 0 | 223 | my ($class, $self, $app, $conf) = @_; | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 75 |  |  | 24 |  | 1165 | $app->vfilter(regexp      => sub { like     $_[1], $_[2] } ); | 
|  | 24 |  |  |  |  | 56 |  | 
| 141 | 75 |  |  | 11 |  | 640 | $app->vfilter(in          => sub { in       $_[1], $_[2] } ); | 
|  | 11 |  |  |  |  | 25 |  | 
| 142 | 75 |  |  | 12 |  | 616 | $app->vfilter(size        => sub { size     $_[1], $_[2][0], $_[2][1] } ); | 
|  | 12 |  |  |  |  | 39 |  | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 75 |  |  | 6 |  | 515 | $app->vfilter(min         => sub { num_ge   $_[1], $_[2] } ); | 
|  | 6 |  |  |  |  | 14 |  | 
| 145 | 75 |  |  | 4 |  | 512 | $app->vfilter(max         => sub { num_le   $_[1], $_[2] } ); | 
|  | 4 |  |  |  |  | 11 |  | 
| 146 | 75 |  |  | 3 |  | 502 | $app->vfilter(equal       => sub { num_eq   $_[1], $_[2] } ); | 
|  | 3 |  |  |  |  | 7 |  | 
| 147 | 75 |  |  | 3 |  | 465 | $app->vfilter('not'       => sub { num_ne   $_[1], $_[2] } ); | 
|  | 3 |  |  |  |  | 9 |  | 
| 148 | 75 |  |  | 5 |  | 502 | $app->vfilter(range       => sub { num_range $_[1], $_[2][0], $_[2][1] } ); | 
|  | 5 |  |  |  |  | 12 |  | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 75 |  |  | 1 |  | 462 | $app->vfilter('lt'        => sub { str_lt   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 4 |  | 
| 151 | 75 |  |  | 1 |  | 472 | $app->vfilter('gt'        => sub { str_gt   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 4 |  | 
| 152 | 75 |  |  | 1 |  | 471 | $app->vfilter('le'        => sub { str_le   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 39 |  | 
| 153 | 75 |  |  | 1 |  | 469 | $app->vfilter('ge'        => sub { str_ge   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 5 |  | 
| 154 | 75 |  |  | 1 |  | 489 | $app->vfilter('cmp'       => sub { str_cmp  $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 5 |  | 
| 155 | 75 |  |  | 1 |  | 1539 | $app->vfilter('eq'        => sub { str_eq   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 4 |  | 
| 156 | 75 |  |  | 1 |  | 634 | $app->vfilter('ne'        => sub { str_ne   $_[1], $_[2] } ); | 
|  | 1 |  |  |  |  | 4 |  | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 75 |  |  |  |  | 254 | return; | 
| 159 |  |  |  |  |  |  | } | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | 1; |