DataLoader

 view release on metacpan or  search on metacpan

t/lib/DataLoader/Test.pm  view on Meta::CPAN

logs each set of keys required to an arrayref. For example, if the
data loader is called twice: first with ('1') and second with ('1','2')
the arrayref will be C<[[1], [1,2]]>.

Any options in C<%options> are passed to the L<DataLoader> constructor.

Returns a 'tuple' of the L<DataLoader> object and the arrayref.

=cut

sub make_test_loader(&@) {
    my ($fn, %options) = @_;
    my @load_calls;
    my $loader = DataLoader->new(sub {
        my @keys = @_;
        push @load_calls, \@keys;
        my @values = map { $fn->() } @keys;
        return Mojo::Promise->resolve(@values);
    }, %options);

    return ($loader, \@load_calls);



( run in 0.774 second using v1.01-cache-2.11-cpan-49f99fa48dc )