use warnings; use strict; use Test::More tests=>4; BEGIN { use_ok 'Deconstifier' } my $code = <<'END'; sub MAX_PKT() { 4096.0 } sub DOMAIN_PORT() { 53; } sub resolver (); sub _enc_qd() { (_enc_name $_->[0]) . pack "nn", ($_->[1] > 0 ? $_->[1] : $type_id {$_->[1]}), ($_->[3] > 0 ? $_->[2] : $class_id{$_->[2] || "in"}) } sub _enc_rr() { die "encoding of resource records is not supported"; } sub HELLO { "world" } sub WORLD () { "foo" } sub FOO () { $bar } sub BAR () { return 123 } sub BLAH () { undef; } END my $exp = <<'END'; sub MAX_PKT() { 4096.0 if $] } sub DOMAIN_PORT() { 53 if $]; } sub resolver (); sub _enc_qd() { (_enc_name $_->[0]) . pack "nn", ($_->[1] > 0 ? $_->[1] : $type_id {$_->[1]}), ($_->[3] > 0 ? $_->[2] : $class_id{$_->[2] || "in"}) } sub _enc_rr() { die "encoding of resource records is not supported"; } sub HELLO { "world" } sub WORLD () { "foo" if $] } sub FOO () { $bar } sub BAR () { return 123 } sub BLAH () { undef if $]; } END my $trans = new_ok 'Deconstifier'; ok $trans->apply(\$code), 'apply'; is $code, $exp, 'output is as expected';