#!/usr/bin/env perl use warnings; use strict; use PPI; use Data::Dump; my $code = <<'ENDCODE'; print "Hello, "; sub Fee { return <<__Fee__; World __Fee__ } sub Blah { return <<'FOO'; Hello FOO } print Fee; ENDCODE my $doc = PPI::Document->new(\$code); for my $sub (@{ $doc->find('PPI::Statement::Sub') }) { # insert the stub (BUT doesn't preserve prototype, attributes, etc.) $sub->insert_after( PPI::Document::Fragment->new(\("sub ".$sub->name." {...}")) ->find_first('PPI::Statement::Sub')->remove ); my $subdoc = PPI::Document::Fragment->new; $subdoc->add_element($sub->remove); print "SUB<<", $subdoc->serialize, ">>\n"; } print "DOC<<", $doc->serialize, ">>\n"; __END__ SUB<> SUB<> DOC<>