Aws-Polly-Select
view release on metacpan or search on metacpan
lib/Aws/Polly/Select.pm view on Meta::CPAN
for my $field(@fields) # Generate methods that get all the values of each attribute of each speaker
{my $s = <<'END';
sub XXX {&fieldValues("XXX")}
END
$s =~ s(XXX) ($field)gs;
eval $s;
$@ and confess $@;
}
}
sub fieldValues($) # All the values a specified field can take
{my ($field) = @_;
my %l;
my @s = @{&speakerDetails};
for my $speaker(@s)
{if (my $v = $speaker->{$field})
{$l{$v}++
}
}
sort keys %l;
}
#-------------------------------------------------------------------------------
# Select speakers
#-------------------------------------------------------------------------------
sub speaker(@) # Select speakers by fields
{my (%selection) = @_; # Selection fields: name=>"regular expression" where the field of that name must match the regular expression regardless of case
my @s;
for my $speaker(@{&speakerDetails}) # Check each speaker
{my $m = 1; # Speaker matches so far
for my $field(keys %selection) # Continue with the speaker as long as they match on all the supplied fields - these fields are our shorter simpler names not AWS's longer more complicated names
{last unless $m;
my $r = $selection{$field}; # Regular expression to match
my $v = $speaker->{$field}; # Value of this field for this speaker
confess "No such field: $field" unless $v;
$m = $v =~ m/$r/; # Case insensitive
( run in 0.620 second using v1.01-cache-2.11-cpan-65fba6d93b7 )