| 1 | package Rose::DBx::TestDB; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use File::Temp 'tempfile'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Rose::DB; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # we want our END to run no matter what (even if ^C) | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use sigtrap qw(die normal-signals error-signals); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | my @TMPFILES; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # check for sqlite version per Rose::DB tests | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | eval { require DBD::SQLite }; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | if ( $@ || $DBD::SQLite::VERSION < 1.08 || $ENV{'RDBO_NO_SQLITE'} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$@ or $DBD::SQLite::VERSION < "1.08" or $ENV{"RDBO_NO_SQLITE"}
$@ or $DBD::SQLite::VERSION < "1.08"
MC/DC0%0/3
$@ or $DBD::SQLite::VERSION < "1.08" or $ENV{"RDBO_NO_SQLITE"}
$@
$DBD::SQLite::VERSION < "1.08"
$ENV{"RDBO_NO_SQLITE"}
Truth table25%1/4
A or B or C
A= $@B= $DBD::SQLite::VERSION < "1.08"C= $ENV{"RDBO_NO_SQLITE"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | croak 'Missing DBD::SQLite 1.08+'; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | elsif ( $DBD::SQLite::VERSION == 1.13 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | carp 'DBD::SQLite 1.13 is broken but we will try testing anyway'; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my ( undef, $filename ) = tempfile(); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | push @TMPFILES, $filename; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | Rose::DB->register_db( | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | domain => 'test', | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | type => 'sqlite', | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | driver => 'sqlite', | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | database => $filename, | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | auto_create => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | connect_options => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | AutoCommit => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ( ( rand() < 0.5 ) ? ( FetchHashKeyName => 'NAME_lc' ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | post_connect_sql => | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | [ 'PRAGMA synchronous = OFF', 'PRAGMA temp_store = MEMORY', ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | Rose::DB->default_domain('test'); | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | Rose::DB->default_type('sqlite'); | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | my $db = Rose::DB->new() | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | or croak "could not create new Rose::DB instance: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return $db; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # in theory File::Temp should clean these up. In theory. | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | END { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
END: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | for my $file (@TMPFILES) { | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | unlink $file unless -e $file; # Sets $! correctly | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | 1 while unlink $file; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Rose::DBx::TestDB - test Rose::DB::Object modules | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | use Rose::DBx::TestDB; | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | my $db = Rose::DBx::TestDB->new; | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # do something with $db | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | exit; | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # END block will automatically clean up all temp db files | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Returns a new Rose::DB object using a temp sqlite database. | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | Peter Karman, C<< <perl at peknet.com> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | C<bug-rose-dbx-testdb at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Rose-DBx-TestDB>. | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | perldoc Rose::DBx::TestDB | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | L<http://annocpan.org/dist/Rose-DBx-TestDB> | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | L<http://cpanratings.perl.org/d/Rose-DBx-TestDB> | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-DBx-TestDB> | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | L<http://search.cpan.org/dist/Rose-DBx-TestDB> | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||
| 124 | Inspired by DBICx::TestDatabase. | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Copyright 2007 Peter Karman, all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||