/usr/share/perl5/Weasel/FindExpanders.pm is in libweasel-perl 0.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | =head1 NAME
Weasel::FindExpanders - Mapping find patterns to xpath locators
=head1 VERSION
0.01
=head1 SYNOPSIS
use Weasel::FindExpanders qw( register_find_expander );
register_find_expander(
'button',
'HTML',
sub {
my %args = @_;
$args{text} =~ s/'/''/g; # quote the quotes (XPath 2.0)
return ".//button[text()='$args{text}']";
});
$session->find($session->page, "@button|{text=>\"whatever\"}");
=cut
package Weasel::FindExpanders;
use strict;
use warnings;
use base 'Exporter';
use Carp;
our @EXPORT_OK = qw| register_find_expander expand_finder_pattern |;
=head1 FUNCTIONS
=over
=item register_find_expander($pattern_name, $group_name, &expander_function)
Registers C<&expander_function> as an expander for C<$pattern_name> in
C<$group_name>.
C<Weasel::Session> selects the expanders to be applied using its C<groups>
attribute.
=cut
# Stores handlers as arrays per group
my %find_expanders;
sub register_find_expander {
my ($pattern_name, $group, $expander_function) = @_;
push @{$find_expanders{$group}{$pattern_name}}, $expander_function;
}
=item expand_finder_pattern($pattern, $args, $groups)
Returns a string of concatenated (using xpath '|' operator) expansions.
When C<$groups> is undef, all groups will be searched for C<pattern_name>.
If the pattern doesn't match '*<pattern_name>|{<arguments>}', the pattern
is returned as the only list/arrayref element.
=cut
sub expand_finder_pattern {
my ($pattern, $args, $groups) = @_;
return $pattern
if ! ($pattern =~ m/^\*([^\|]+)/);
my $name = $1;
croak "No expansions registered (while expanding '$pattern')"
if scalar(keys %find_expanders) == 0;
$groups //= [ keys %find_expanders ]; # undef --> unrestricted
# Using eval below to transform a hash-in-string to a hash efficiently
my @matches;
for my $group (@$groups) {
next if ! exists $find_expanders{$group}{$name};
push @matches,
reverse map { $_->(%$args) } @{$find_expanders{$group}{$name}};
}
croak "No expansions matching '$pattern'"
if ! @matches;
return join "\n|", @matches;
}
=back
=cut
1;
|