| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Routine::AutoClear; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$Test::Routine::AutoClear::VERSION = '0.001'; # TRIAL |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
# ABSTRACT: Enables autoclearing attrs in Test::Routines |
|
6
|
1
|
|
|
1
|
|
774
|
use Test::Routine (); |
|
|
1
|
|
|
|
|
377804
|
|
|
|
1
|
|
|
|
|
29
|
|
|
7
|
1
|
|
|
1
|
|
11
|
use Moose::Exporter; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
|
10
|
|
|
|
|
|
|
with_meta => [qw{has}], |
|
11
|
|
|
|
|
|
|
also => 'Test::Routine', |
|
12
|
|
|
|
|
|
|
); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub init_meta { |
|
15
|
1
|
|
|
1
|
0
|
64
|
my($class, %arg) = @_; |
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
4
|
my $meta = Moose::Role->init_meta(%arg); |
|
18
|
1
|
|
|
|
|
2303
|
my $role = $arg{for_class}; |
|
19
|
1
|
|
|
|
|
3
|
Moose::Util::apply_all_roles($role, 'Test::Routine::DoesAutoClear'); |
|
20
|
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
1040
|
return $meta; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub has { |
|
25
|
1
|
|
|
1
|
0
|
110
|
my($meta, $name, %options) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
4
|
if (delete $options{autoclear}) { |
|
28
|
1
|
|
|
|
|
1
|
push @{$options{traits}}, 'AutoClear' |
|
|
1
|
|
|
|
|
4
|
|
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$meta->add_attribute( |
|
32
|
1
|
|
|
|
|
8
|
$name, |
|
33
|
|
|
|
|
|
|
%options, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
1; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Test::Routine::AutoClear - Enables autoclearing attrs in Test::Routines |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 VERSION |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
version 0.001 |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use Test::Routine::AutoClear; |
|
52
|
|
|
|
|
|
|
use Test::More; |
|
53
|
|
|
|
|
|
|
use File::Tempdir; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has _tempdir => ( |
|
56
|
|
|
|
|
|
|
is => 'ro', |
|
57
|
|
|
|
|
|
|
isa => 'Int', |
|
58
|
|
|
|
|
|
|
builder => '_build_tempdir', |
|
59
|
|
|
|
|
|
|
lazy => 1, |
|
60
|
|
|
|
|
|
|
autoclear => 1, |
|
61
|
|
|
|
|
|
|
handles => { |
|
62
|
|
|
|
|
|
|
tempdir => 'name', |
|
63
|
|
|
|
|
|
|
}, |
|
64
|
|
|
|
|
|
|
); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _build_tempdir { |
|
67
|
|
|
|
|
|
|
File::Tempdir->new(); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
And now all the tests that use a tempdir in your test routine will get a |
|
71
|
|
|
|
|
|
|
fresh Tempdir |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
When I'm writing tests with L<Test::Routine> I find myself writing code like |
|
76
|
|
|
|
|
|
|
this all the time: |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has counter => ( |
|
79
|
|
|
|
|
|
|
is => ro, |
|
80
|
|
|
|
|
|
|
lazy => 1, |
|
81
|
|
|
|
|
|
|
default => 0 |
|
82
|
|
|
|
|
|
|
lazy => 1, |
|
83
|
|
|
|
|
|
|
clearer => 'reset_counter', |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over 4 |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item * |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L<Test::Routine> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 AUTHOR |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Piers Cawley <pdcawley@bofh.org.uk> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Piers Cawley. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
105
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |
|
111
|
|
|
|
|
|
|
|