1use Test; 2BEGIN { $| = 1; plan(tests => 4); chdir 't' if -d 't'; } 3use blib; 4 5## 6## creating a new recipe file programmatically 7## flush to disk and read again 8## 9 10use Mail::Procmailrc; 11 12my $pmrc = new Mail::Procmailrc; 13 14## push a variable assignment 15my $v1 = new Mail::Procmailrc::Variable(); 16$v1->lval('FOO'); 17$v1->rval('bar'); 18$pmrc->push($v1); 19 20my $v2 = new Mail::Procmailrc::Variable(); 21$v2->lval('HORK'); 22$v2->rval(''); 23$pmrc->push($v2); 24ok( $v2->stringify, "HORK=" ); 25 26## push another variable assignment 27$pmrc->push( new Mail::Procmailrc::Variable(['PMDIR=$HOME/.procmail'])); 28 29## push an empty line 30$pmrc->push( new Mail::Procmailrc::Literal ); 31 32## push an entire recipe 33my $rec = new Mail::Procmailrc::Recipe; 34$rec->flags(':0B:'); 35$rec->info('## put spam away'); 36$rec->conditions([ q(* 1^0 this is not spam), 37 q(* 1^0 please read this), 38 q(* 1^0 urgent assistance), 39 ]); 40$rec->action('$PMDIR/spam'); 41$pmrc->push($rec); 42 43## flush 44$pmrc->flush("_tmp.$$"); 45 46my $pmrc_new = new Mail::Procmailrc("_tmp.$$"); 47ok( $pmrc_new->dump(), $pmrc->dump() ); 48ok( scalar(@{$pmrc_new->variables}), 3 ); 49 50## test that what we created matches what we imagined 51ok( $pmrc_new->dump(), <<'_RECIPE_' ); 52FOO=bar 53HORK= 54PMDIR=$HOME/.procmail 55 56:0B: 57## put spam away 58* 1^0 this is not spam 59* 1^0 please read this 60* 1^0 urgent assistance 61$PMDIR/spam 62_RECIPE_ 63 64unlink("_tmp.$$"); 65 66exit; 67