« Environment/Plugin/Apache2/Apache2/Filter.pm
↑ Summary
Environment/Plugin/Apache2/Apache2/Request.pm »
| 1 | package Test::Environment::Plugin::Dump; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Test::Environment::Plugin::Dump - Dump files reader plugin | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | use Test::Environment qw{ | ||||||||||
| 10 | Dump | ||||||||||
| 11 | }; | ||||||||||
| 12 | |||||||||||
| 13 | dump_with_name('some_file.txt'); | ||||||||||
| 14 | |||||||||||
| 15 | set_dumps_folder($FindBin::Bin.'/dumps2'); | ||||||||||
| 16 | dump_with_name('some_other_file.txt'); | ||||||||||
| 17 | |||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||
| 19 | |||||||||||
| 20 | This plugin will export 'dump_with_name' and 'set_dumps_folder' functions. | ||||||||||
| 21 | |||||||||||
| 22 | set_dumps_folder($path) will set the root path where dump files will be looked | ||||||||||
| 23 | up. | ||||||||||
| 24 | |||||||||||
| 25 | dump_with_name($file_name) will return | ||||||||||
| 26 | |||||||||||
| 27 | File::Slurp::read_file($dump_folder.'/'.$file_name) | ||||||||||
| 28 | |||||||||||
| 29 | Default $dump_folder is $FindBin::Bin.'/dumps'. | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 35 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | 1 | our $VERSION = "0.07"; | |||||||||
| 38 | |||||||||||
| 39 | 1 | ▶ | use base qw{ Exporter }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 1 | our @EXPORT = qw{ | |||||||||
| 41 | dump_with_name | ||||||||||
| 42 | set_dumps_folder | ||||||||||
| 43 | }; | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | use Carp::Clan; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 46 | 1 | ▶ | use File::Slurp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 1 | ▶ | use FindBin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | =head1 FUNCTIONS | ||||||||||
| 51 | |||||||||||
| 52 | =head2 import | ||||||||||
| 53 | |||||||||||
| 54 | All functions are exported 2 levels up. That is to the use Test::Environment caller. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||
| 59 | 1 | my $package = shift; | |||||||||
| 60 | |||||||||||
| 61 | # export symbols two levels up - to the Test::Environment caller | ||||||||||
| 62 | 1 | __PACKAGE__->export_to_level(2, $package, @EXPORT); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | |||||||||||
| 66 | =head2 dump_with_name($name) | ||||||||||
| 67 | |||||||||||
| 68 | Returns read_file($dumps_folder.'/'.$name). | ||||||||||
| 69 | |||||||||||
| 70 | =cut | ||||||||||
| 71 | |||||||||||
| 72 | 1 | our $dumps_folder = $FindBin::Bin.'/dumps'; | |||||||||
| 73 | 0 | ▶ | sub dump_with_name { | ||||||||
|
Subroutine
dump_with_name: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 74 | 0 | my $name = shift; | |||||||||
| 75 | |||||||||||
| 76 | 0 | ▶ | croak 'please set dump name' if not defined $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | |||||||||||
| 78 | 0 | $name = $dumps_folder.'/'.$name; | |||||||||
| 79 | 0 | ▶ | croak 'file not found "'.$name.'"' if not -f $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 0 | return read_file($name); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | =head2 set_dumps_folder($folder_name) | ||||||||||
| 86 | |||||||||||
| 87 | Set dumps root folder to $folder_name. | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub set_dumps_folder { | ||||||||
|
Subroutine
set_dumps_folder: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 92 | 0 | my $folder_name = shift; | |||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | croak 'pass folder name' if not defined $folder_name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | ▶ | croak 'folder not found' if not -d $folder_name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | 0 | $dumps_folder = $folder_name; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 1 | 1; | |||||||||
| 101 | |||||||||||
| 102 | |||||||||||
| 103 | =head1 SEE ALSO | ||||||||||
| 104 | |||||||||||
| 105 | Test::Environment L<http://search.cpan.org/perldoc?Test::Environment> | ||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Jozef Kutej - E<lt>jozef@kutej.netE<gt> | ||||||||||
| 110 | |||||||||||
| 111 | =cut | ||||||||||
| 112 | |||||||||||