CIPP

 view release on metacpan or  search on metacpan

bin/cipp-link-static  view on Meta::CPAN

		if ( /request->call_include_subroutine/ ) {
			# parse file
			$line = <$read_fh>;
			my ($file) = $line =~ /=>\s+['"](.*?)['"]/;
			next if $inserted_includes{$file};
			$inserted_includes{$file} = 1;
			my $full_path = $request->resolve_inc_filename (
				file => $file,
			);
			my $fh = FileHandle->new;
			open ($fh, $full_path) or die "can't read $full_path";
			my $perl_code;
			while ( <$fh> ) {
				last if /^sub/;
			}
			$perl_code = $_;
			while ( <$fh> ) {
				$perl_code .= $_;
			}
			close $fh;
			$insert_include_code .=
				"\n".
				"CIPP::Runtime::Request->add_include_subroutine (\n".
				"\tfile => '$file',\n".
				"\tcode => $perl_code".
				");\n";
			print ".";
		}
	}

	chdir $cwd;

	if ( $insert_include_code ) {
		my $write_fh = FileHandle->new;
		open ($write_fh, ">$tmp_file") or die "can't write $tmp_file";

		# insert include code somewhere at the top of the file
		seek ($read_fh, 0, 0);

		my $code_inserted;
		while ( <$read_fh> ) {
			if ( not $code_inserted and /^\$_cipp_project->new_request/ ) {
				print $write_fh $_;
				my $line = <$read_fh>;
				print $write_fh $line;
				$line = <$read_fh>;
				print $write_fh $line;
				$line = <$read_fh>;
				print $write_fh $line;
				print $write_fh $insert_include_code;
				$code_inserted = 1;
				next;
			}
			print $write_fh $_;
		}
		
		close $write_fh;
		close $read_fh;
		
		rename ($tmp_file, $file);
		chmod 0775, $file;
		link_static ( file => $file );
	} else {
		close $read_fh;
	}

	1;
}

1;



( run in 0.866 second using v1.01-cache-2.11-cpan-39bf76dae61 )