App-Asciio

 view release on metacpan or  search on metacpan

setup/import_export/perl.pl  view on Meta::CPAN

		{
		push @asciio_pods, "=for asciio $section" ;
		last ;
		}
	}

#todo: handle files without asciio section
#todo: handle files with multiple asciio sections

my $asciio_section = $asciio_pods[0] ;
my @asciio_lines = split "\n", $asciio_section ;
my $asciio_header = shift @asciio_lines ;

#~ use Data::TreeDumper ;
#~ print DumpTree \@asciio_lines, 'asciio_lines' ;

my $whole_file = read_file($file_name) ;

if($whole_file =~ /(.*)$asciio_header.*?(\n=.*)/sm)
	{
	($header, $footer) = ($1, $2) ;
	}
else
	{
	die "get_base64_data: Can't find the text we just extracted!" ;
	}
	
my ($for, $asciio, $width, $name) = split ' ', $asciio_header ;

my $base64 = '' ;

for my $asciio_line (@asciio_lines)
	{
	substr($asciio_line, 0, $width + $BASE64_HEADER_SIZE + 1, '') ; # strip to base64
	$base64 .= $asciio_line . "\n" ;
	}

return ($base64, $header, $footer) ;
}

#----------------------------------------------------------------------------------------------------------------------------

sub export_pod
{
my ($self, $elements_to_save, $file, $data)  = @_ ;

my ($base_name, $path, $extension) = File::Basename::fileparse($file, ('\..*')) ;
my $file_name = $base_name . $extension ;

my @ascii_representation = $self->transform_elements_to_ascii_array() ;
my $longest_line =  max( map{length} @ascii_representation) ;

my $compressed_self = compress($self->serialize_self() .  '$VAR1 ;') ;

my $base64 =MIME::Base64::encode($compressed_self, '') ;
my $base64_chunk_size = int((length($base64) / @ascii_representation) + 1) ;

if($self->{CREATE_BACKUP} && -e $file)
	{
	use File::Copy;
	copy($file,"$file.bak") or die "export_pod: Copy failed while making backup copy: $!";		
	}

open POD, ">:encoding(utf8)",  $file_name or die "export_pod: can't open file '$file_name'!\n";

print POD $data->{HEADER} || '' ;
print POD "=for asciio $longest_line $base_name\n\n" ;

for my $diagram_line (@ascii_representation)
	{
	my $padding = ' ' x ($longest_line - length($diagram_line)) ;
	my $base64_chunk = substr($base64, 0, $base64_chunk_size, '') || '' ;
	
	print POD ' ' ,  $diagram_line, $padding, $BASE64_HEADER, $base64_chunk, "\n"
	}

print POD $data->{FOOTER} || "\n=cut\n\n";
close POD ;

return $file ;
}

 



( run in 1.234 second using v1.01-cache-2.11-cpan-ceb78f64989 )