Test::Routine::AutoClear - Enables autoclearing attrs in Test::Routines
version 0.002
use Test::Routine::AutoClear; use Test::More; use File::Tempdir; has _tempdir => ( is => 'ro', isa => 'Int', builder => '_build_tempdir', lazy => 1, autoclear => 1, handles => { tempdir => 'name', }, ); sub _build_tempdir { File::Tempdir->new(); }
And now all the tests that use a tempdir in your test routine will get a fresh Tempdir
When I'm writing tests with Test::Routine I find myself writing code like this all the time:
has counter => ( is => ro, lazy => 1, default => 0 lazy => 1, clearer => 'reset_counter', ); after run_test => sub { shift->reset_counter; };
And after about the first time, I got bored of doing this. So I started to fix it, and here's my first cut.
Lots. Including, but not limited to:
The interface is still very fluid. I make no promises about interface stability.
I'm pretty sure that if you end up mixing in multiple roles that use this role then you'll end up clearing your attributes lots of times.
I think it's reasonable to expect that resetting an attribute that didn't get set via a builder should reset the value to the initial value that was set via the instantiation params. Or maybe autoclear => 1 should imply init_arg => undef.
autoclear => 1
init_arg => undef
Test::Routine
Piers Cawley <pdcawley@bofh.org.uk>
This software is copyright (c) 2012 by Piers Cawley.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test::Routine::AutoClear, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Routine::AutoClear
CPAN shell
perl -MCPAN -e shell install Test::Routine::AutoClear
For more information on module installation, please visit the detailed CPAN module installation guide.