# Parse eine einzelne Komponente sub _parse_part{ my $self = shift; my $head = shift; my $in = $self->{stdin}; my $boundary = $self->{boundary}; # nun lese die binary my $tmp = IO::String->new; # boundary detection my @fifo = split('', $boundary); my $boundary_detect = 4; while( read($in, my $byte, 1) ){ shift @fifo; push @fifo, $byte; $tmp->print($byte); if( join('', @fifo) eq $boundary ){ $boundary_detect = 2; last; } } my $content = ''; $tmp->truncate( $tmp->tell() - length($boundary) - $boundary_detect ); $tmp->seek(0,0); while(read($tmp, my $buffer, 1024)){ $content .= $buffer; } $tmp->seek(0,0); # parse header Angaben my $content_type = do{ $head =~ /Content-Type: ?(.*)/s; $1 ? unpack "A*", pack "A*", $1 : ''; }; my $name = do{ $head =~ /name="(.*?)"/s; $1 ? $1 : ''; }; my $filename = do{ $head =~ /filename="(.*?)"/s; $1 ? $1 : ''; }; push @{$self->{param}{$name}}, $filename ? { name => $name, content_type => $content_type, filename => $filename, iohandle => $tmp, content_length => length($content), } : $content; }