1# parse() Handlers argument test 2# $Id: handlers.t,v 1.3 2000/07/19 23:13:24 mfowler Exp $ 3 4# This script verifies the Handlers argument to parse() works as advertised. 5# Verifies it accepts a code or hash reference, properly calls the given code 6# reference, and properly sets the referred hash. 7 8 9use Parse::PerlConfig; 10 11use lib qw(t); 12use parse::testconfig qw(ok); 13 14use strict; 15use vars qw($tconf $test_handler %test_handler); 16 17 18$tconf = parse::testconfig->new('test.conf'); 19 20$tconf->tests(4 + $tconf->verify_parsed() * 4); 21$tconf->ok_object(); 22 23 24# test a hash handler 25Parse::PerlConfig::parse( 26 File => $tconf->file_path(), 27 Handler => \%test_handler, 28); 29 30$tconf->verify_parsed(\%test_handler); 31 32 33 34# test a code handler 35Parse::PerlConfig::parse( 36 File => $tconf->file_path(), 37 Handler => \&test_handler, 38); 39 40ok(defined $test_handler); 41ok($test_handler); 42 43 44 45undef %test_handler; 46undef $test_handler; 47 48 49 50# test a code and a hash handler 51Parse::PerlConfig::parse( 52 File => $tconf->file_path(), 53 Handlers => [\%test_handler, \&test_handler], 54); 55 56$tconf->verify_parsed(\%test_handler); 57ok(defined $test_handler); 58ok($test_handler); 59 60 61 62 63sub test_handler { 64 $test_handler = 1; 65 $tconf->verify_parsed(shift); 66} 67