| 1 | # | ||||||||||
| 2 | # This file is part of WWW-DaysOfWonder-Memoir44 | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2009 by Jerome Quelin. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | 2 | ▶ | use 5.012; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | package WWW::DaysOfWonder::Memoir44::Filter; | ||||||||||
| 14 | # ABSTRACT: filter object | ||||||||||
| 15 | 2 | $WWW::DaysOfWonder::Memoir44::Filter::VERSION = '3.000'; | |||||||||
| 16 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 2 | ▶ | use MooseX::Has::Sugar; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 2 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 2 | with 'MooseX::Getopt::GLD'; | |||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | use WWW::DaysOfWonder::Memoir44::Types; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | # -- public attributes | ||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | 2 | has ids => ( | |||||||||
| 30 | rw, auto_deref, | ||||||||||
| 31 | isa => 'ArrayRef[Int]', | ||||||||||
| 32 | predicate => 'has_ids', | ||||||||||
| 33 | traits => [ qw{ Getopt } ], | ||||||||||
| 34 | cmd_aliases => [ qw{ i } ], | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | 2 | has name => ( | |||||||||
| 38 | rw, | ||||||||||
| 39 | isa => 'Str', | ||||||||||
| 40 | predicate => 'has_name', | ||||||||||
| 41 | traits => [ qw{ Getopt } ], | ||||||||||
| 42 | cmd_aliases => [ qw{ n } ], | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | 2 | has operation => ( | |||||||||
| 46 | rw, | ||||||||||
| 47 | isa => 'Str', | ||||||||||
| 48 | predicate => 'has_operation', | ||||||||||
| 49 | traits => [ qw{ Getopt } ], | ||||||||||
| 50 | cmd_aliases => [ qw{ o } ], | ||||||||||
| 51 | ); | ||||||||||
| 52 | |||||||||||
| 53 | 2 | has front => ( | |||||||||
| 54 | rw, | ||||||||||
| 55 | isa => 'Str', | ||||||||||
| 56 | predicate => 'has_front', | ||||||||||
| 57 | traits => [ qw{ Getopt } ], | ||||||||||
| 58 | cmd_aliases => [ qw{ w } ], | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 2 | has format => ( | |||||||||
| 62 | rw, | ||||||||||
| 63 | isa => 'Format', | ||||||||||
| 64 | predicate => 'has_format', | ||||||||||
| 65 | traits => [ qw{ Getopt } ], | ||||||||||
| 66 | cmd_aliases => [ qw{ fmt f } ], | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | 2 | has board => ( | |||||||||
| 70 | rw, | ||||||||||
| 71 | isa => 'Board', | ||||||||||
| 72 | predicate => 'has_board', | ||||||||||
| 73 | traits => [ qw{ Getopt } ], | ||||||||||
| 74 | cmd_aliases => [ qw{ b } ], | ||||||||||
| 75 | ); | ||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | 2 | has tp => ( rw, isa=>'Bool' ); | |||||||||
| 80 | 2 | has ef => ( rw, isa=>'Bool' ); | |||||||||
| 81 | 2 | has mt => ( rw, isa=>'Bool' ); | |||||||||
| 82 | 2 | has pt => ( rw, isa=>'Bool' ); | |||||||||
| 83 | 2 | has ap => ( rw, isa=>'Bool' ); | |||||||||
| 84 | 2 | has bm => ( rw, isa=>'Bool' ); | |||||||||
| 85 | 2 | has cb => ( rw, isa=>'Bool' ); | |||||||||
| 86 | |||||||||||
| 87 | |||||||||||
| 88 | |||||||||||
| 89 | 2 | has languages => ( | |||||||||
| 90 | rw, auto_deref, | ||||||||||
| 91 | isa => 'ArrayRef[Str]', | ||||||||||
| 92 | predicate => 'has_languages', | ||||||||||
| 93 | traits => [ qw{ Getopt } ], | ||||||||||
| 94 | cmd_aliases => [ qw{ lang l } ], | ||||||||||
| 95 | ); | ||||||||||
| 96 | |||||||||||
| 97 | 2 | has rating => ( | |||||||||
| 98 | rw, coerce, | ||||||||||
| 99 | isa => 'Int_0_3', | ||||||||||
| 100 | predicate => 'has_rating', | ||||||||||
| 101 | traits => [ qw{ Getopt } ], | ||||||||||
| 102 | cmd_aliases => [ qw{ rate r } ], | ||||||||||
| 103 | ); | ||||||||||
| 104 | |||||||||||
| 105 | |||||||||||
| 106 | # -- public methods | ||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | 0 | ▶ | sub as_grep_clause { | ||||||||
|
Subroutine
as_grep_clause: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||
| 110 | 0 | my $self = shift; | |||||||||
| 111 | 0 | my @clauses; | |||||||||
| 112 | |||||||||||
| 113 | # ** filtering on scenario information | ||||||||||
| 114 | # - ids | ||||||||||
| 115 | 0 | ▶ | if ( $self->has_ids ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 0 | my $clause = join( '||', map { "\$_->id == $_" } $self->ids ); | |||||||||
| 117 | 0 | push @clauses, "($clause)"; | |||||||||
| 118 | } | ||||||||||
| 119 | |||||||||||
| 120 | # - name | ||||||||||
| 121 | 0 | ▶ | push @clauses, '$_->name =~ qr{' . $self->name . '}i' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | if $self->has_name; | ||||||||||
| 123 | |||||||||||
| 124 | # - operation | ||||||||||
| 125 | 0 | ▶ | push @clauses, '$_->operation =~ qr{' . $self->operation . '}i' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | if $self->has_operation; | ||||||||||
| 127 | |||||||||||
| 128 | # - front | ||||||||||
| 129 | 0 | ▶ | push @clauses, '$_->front =~ qr{' . $self->front . '}i' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | if $self->has_front; | ||||||||||
| 131 | |||||||||||
| 132 | # - format | ||||||||||
| 133 | 0 | ▶ | push @clauses, '$_->format eq q{' . $self->format . '}' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | if $self->has_format; | ||||||||||
| 135 | |||||||||||
| 136 | # - board | ||||||||||
| 137 | 0 | ▶ | push @clauses, '$_->board eq q{' . $self->board . '}' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | if $self->has_board; | ||||||||||
| 139 | |||||||||||
| 140 | # ** filtering on extensions | ||||||||||
| 141 | 0 | foreach my $expansion ( qw{ tp ef pt mt ap } ) { | |||||||||
| 142 | 0 | ▶ | next unless defined $self->$expansion; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 143 | 0 | my $clause = '$_->need_'; | |||||||||
| 144 | 0 | ▶ | $clause = "!$clause" unless $self->$expansion; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | 0 | push @clauses, $clause . $expansion; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | # ** filtering on meta-information | ||||||||||
| 149 | # - languages | ||||||||||
| 150 | 0 | ▶ | if ( $self->has_languages ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 151 | 0 | my $clause = 'join(",",$_->languages) =~ /\Q'; | |||||||||
| 152 | 0 | $clause .= join "\\E|\\Q", $self->languages; | |||||||||
| 153 | 0 | $clause .= '\E/'; | |||||||||
| 154 | 0 | push @clauses, $clause; | |||||||||
| 155 | } | ||||||||||
| 156 | |||||||||||
| 157 | # - rating | ||||||||||
| 158 | 0 | ▶ | push @clauses, '$_->rating >= ' . $self->rating | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | if $self->has_rating; | ||||||||||
| 160 | |||||||||||
| 161 | 0 | my $grep = "sub { " . join(" && ", (1,@clauses)) . " }"; | |||||||||
| 162 | 0 | return eval $grep; | |||||||||
| 163 | } | ||||||||||
| 164 | |||||||||||
| 165 | |||||||||||
| 166 | 2 | 1; | |||||||||
| 167 | |||||||||||
| 168 | __END__ | ||||||||||