The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::DBIx::Class::Stats - test statistics about your DBIx::Class calls

SYNOPSIS

Run a subtest with a debugging object (Test::DBIx::Class::Stats::Profiler) set to capture the number of calls that have been made to the database. This may be useful to check your assumptions about prefetching, etc.

    use Test::More;
    use Test::DBIx::Class::Stats;

    # if you are using Test::DBIx::Class or similar, we can get the 
    # database handle from the `Schema` method
    use Test::DBIx::Class;

    with_stats 'test 1', sub {
        my $stats = shift;

        my $rs = Schema->resultset('Foo')->search();
        is $stats->call_count, 0, 'No calls on preparing RS';

        my @foo = $rs->all;
        is $stats->call_count, 1, '1 call after preparing RS';
    };

    # alternatively, we can pass it in explicitly:
    
    my $db = Schema
    with_stats 'test 2', $db, sub {
        ...
    };

EXPORTED FUNCTIONS

with_stats $name, [$db], $code

The Test::DBIx::Class::Stats::Profiler object is created for the database and is passed to your code reference as its first and only argument.

If $db is not passed, the caller's Schema function will be called. This is designed to work with Test::DBIx::Class.

AUTHOR

osfameron <osfameron@cpan.org> 2014-2017 Alexander Hartmaier <abraxxa@cpan.org> 2017