11 if ( ! -d 'DBM_Filter')
13 mkdir 'DBM_Filter', 0777
14 || die "Cannot create directory 'DBM_Filter': $!\n" ;
20 my $filename = shift ;
22 open F, ">$filename" || croak "Cannot open $filename: $!" ;
32 print "# runFilter $name\n" ;
33 my $filename = "DBM_Filter/$name.pm";
34 $filter = "package DBM_Filter::$name ;\n$filter"
35 unless $filter =~ /^\s*package/ ;
37 writeFile($filename, $filter);
38 eval { $db->Filter_Push($name) };
43 use Test::More tests => 21;
45 BEGIN { use_ok('DBM_Filter') };
46 BEGIN { use_ok('SDBM_File') };
47 BEGIN { use_ok('Fcntl') };
50 END { unlink <Op_dbmx*>; }
54 $db = tie(%h1, 'SDBM_File','Op_dbmx', O_RDWR|O_CREAT, 0640) ;
56 ok $db, "tied to SDBM_File ok";
61 eval { $db->Filter_Push() ; };
62 like $@, qr/^Filter_Push: no parameters present/,
63 "croak if not parameters passed to Filter_Push";
65 eval { $db->Filter_Push("unknown_class") ; };
66 like $@, qr/^Filter_Push: Cannot Load DBM Filter 'DBM_Filter::unknown_class'/,
67 "croak on unknown class" ;
69 eval { $db->Filter_Push("Some::unknown_class") ; };
70 like $@, qr/^Filter_Push: Cannot Load DBM Filter 'Some::unknown_class'/,
71 "croak on unknown fully qualified class" ;
73 eval { $db->Filter_Push('Store') ; };
74 like $@, qr/^Filter_Push: not even params/,
75 "croak if not passing even number or params to Filter_Push";
77 runFilter('bad1', <<'EOM');
78 package DBM_Filter::bad1 ;
82 like $@, qr/^Filter_Push: No methods \(Filter, Fetch or Store\) found in class 'DBM_Filter::bad1'/,
83 "croak if none of Filter/Fetch/Store in filter" ;
86 runFilter('bad2', <<'EOM');
87 package DBM_Filter::bad2 ;
97 like $@, qr/^Filter_Push: 'DBM_Filter::bad2::Filter' did not return a hash reference./,
98 "croak if Filter doesn't return hash reference" ;
100 runFilter('bad3', <<'EOM');
101 package DBM_Filter::bad3 ;
105 return { BadKey => sub { } } ;
112 like $@, qr/^Filter_Push: Unknown key 'BadKey'/,
113 "croak if bad keyword returned from Filter";
115 runFilter('bad4', <<'EOM');
116 package DBM_Filter::bad4 ;
120 return { Store => "abc" } ;
126 like $@, qr/^Filter_Push: value associated with key 'Store' is not a code reference/,
127 "croak if not a code reference";
129 runFilter('bad5', <<'EOM');
130 package DBM_Filter::bad5 ;
140 like $@, qr/^Filter_Push: expected both Store & Fetch - got neither/,
141 "croak if neither fetch or store is present";
143 runFilter('bad6', <<'EOM');
144 package DBM_Filter::bad6 ;
148 return { Store => sub {} } ;
154 like $@, qr/^Filter_Push: expected both Store & Fetch - got Store/,
155 "croak if store is present but fetch isn't";
157 runFilter('bad7', <<'EOM');
158 package DBM_Filter::bad7 ;
162 return { Fetch => sub {} } ;
168 like $@, qr/^Filter_Push: expected both Store & Fetch - got Fetch/,
169 "croak if fetch is present but store isn't";
171 runFilter('bad8', <<'EOM');
172 package DBM_Filter::bad8 ;
181 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad8'/,
182 "croak if Fetch, Store and Filter";
184 runFilter('bad9', <<'EOM');
185 package DBM_Filter::bad9 ;
193 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad9'/,
194 "croak if Store and Filter";
196 runFilter('bad10', <<'EOM');
197 package DBM_Filter::bad10 ;
205 like $@, qr/^Filter_Push: Can't mix Filter with Store and Fetch in class 'DBM_Filter::bad10'/,
206 "croak if Fetch and Filter";
208 runFilter('bad11', <<'EOM');
209 package DBM_Filter::bad11 ;
216 like $@, qr/^Filter_Push: Missing method 'Store' in class 'DBM_Filter::bad11'/,
217 "croak if Fetch but no Store";
219 runFilter('bad12', <<'EOM');
220 package DBM_Filter::bad12 ;
227 like $@, qr/^Filter_Push: Missing method 'Fetch' in class 'DBM_Filter::bad12'/,
228 "croak if Store but no Fetch";
232 use warnings FATAL => 'untie';
234 is $@, '', "untie without inner references" ;