CHI/t/Config.pm

filter: Statementstmt 100% 74 / 74 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 2 totaltotal 97.8% 90 / 92 SCAR 11.0
CC
3
Cov
100%
_create
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« CHI/Test.pm ↑ Summary CHI/t/RequiredModules.pm »
1 package CHI::t::Config;
2 1 $CHI::t::Config::VERSION = '0.59';
3 1 ▶use CHI::Util qw(dump_one_line);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use CHI::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(CHI::Test::Class);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my $root_dir = tempdir( 'CHI-t-Config-XXXX', TMPDIR => 1, CLEANUP => 1 );
11  
12 1 my %config = (
13 storage => {
14 memory => { driver => 'Memory', global => 1 },
15 file => { driver => 'File', root_dir => $root_dir },
16 },
17 namespace => {
18 'Foo' => { storage => 'file' },
19 'Bar' => { storage => 'file', depth => 3 },
20 },
21 defaults => { storage => 'memory' },
22 );
23  
24 {
25 package My::CHI;
26 1 $My::CHI::VERSION = '0.59';
27 1 ▶use base qw(CHI);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 My::CHI->config( {%config} );
29 }
30  
31 {
32 1 package My::CHI::Subclass;
33 1 $My::CHI::Subclass::VERSION = '0.59';
34 1 ▶use base qw(My::CHI);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 }
36  
37 {
38 1 package My::CHI::Memo;
39 1 $My::CHI::Memo::VERSION = '0.59';
40  
41 1 ▶ use base qw(CHI);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 My::CHI::Memo->config( { %config, memoize_cache_objects => 1 } );
43 }
44  
45 sub _create {
46 5 ▶ my ( $params, $checks ) = @_;
Subroutine _create: called CC=3 SCAR=11.0
47  
48 5 my $desc = dump_one_line($params);
49 5 foreach my $class (qw(My::CHI My::CHI::Subclass)) {
50 10 my $cache = $class->new(%$params);
51 10 ▶ while ( my ( $key, $value ) = each(%$checks) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$checks) 50 10 60
52 50 is( $cache->$key, $value, "$key == $value ($desc)" );
53 }
54 }
55 }
56  
57 sub test_config : Tests {
58 1 ▶ my $self = shift;
Subroutine test_config: called CC=1 SCAR=0.0
Pod undocumented
59  
60 1 _create(
61 { namespace => 'Foo' },
62 {
63 namespace => 'Foo',
64 storage => 'file',
65 short_driver_name => 'File',
66 root_dir => $root_dir,
67 depth => 2
68 },
69 );
70 1 _create(
71 { namespace => 'Bar' },
72 {
73 namespace => 'Bar',
74 storage => 'file',
75 short_driver_name => 'File',
76 root_dir => $root_dir,
77 depth => 3
78 }
79 );
80 1 _create(
81 { namespace => 'Foo', depth => 4 },
82 {
83 namespace => 'Foo',
84 storage => 'file',
85 short_driver_name => 'File',
86 root_dir => $root_dir,
87 depth => 4
88 }
89 );
90 1 _create(
91 { namespace => 'Bar', depth => 4 },
92 {
93 namespace => 'Bar',
94 storage => 'file',
95 short_driver_name => 'File',
96 root_dir => $root_dir,
97 depth => 4
98 }
99 );
100  
101 1 my %new_config = %config;
102 1 $new_config{namespace}->{'Bar'}->{depth} = 5;
103 1 My::CHI->config( {%new_config} );
104 1 _create(
105 { namespace => 'Bar' },
106 {
107 namespace => 'Bar',
108 storage => 'file',
109 short_driver_name => 'File',
110 root_dir => $root_dir,
111 depth => 5
112 }
113 );
114 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
115  
116 sub test_memoize : Tests {
117 1 ▶ my $cache1 = My::CHI::Memo->new( namespace => 'Foo' );
Subroutine test_memoize: called CC=1 SCAR=0.0
Pod undocumented
118 1 my $cache2 = My::CHI::Memo->new( namespace => 'Foo' );
119 1 is( $cache1, $cache2, "same - namespace Foo" );
120  
121 1 my $cache3 = My::CHI::Memo->new( namespace => 'Bar', depth => 4 );
122 1 my $cache4 = My::CHI::Memo->new( namespace => 'Bar', depth => 4 );
123 1 isnt( $cache3, $cache4, "different - namespace Bar" );
124  
125 1 My::CHI::Memo->clear_memoized_cache_objects();
126 1 my $cache5 = My::CHI::Memo->new( namespace => 'Foo' );
127 1 my $cache6 = My::CHI::Memo->new( namespace => 'Foo' );
128 1 is( $cache5, $cache6, "same - namespace Foo" );
129 1 isnt( $cache1, $cache3, "different - post-clear" );
130  
131 1 my $cache7 = My::CHI->new( namespace => 'Foo' );
132 1 my $cache8 = My::CHI->new( namespace => 'Foo' );
133 1 isnt( $cache7, $cache8, "different - namespace Foo - no memoization" );
134 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 1 1;
« CHI/Test.pm ↑ Summary CHI/t/RequiredModules.pm »