| 1 | # Mail::MboxParser - object-oriented access to UNIX-mailboxes | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Body.pm - the (textual) body of an email | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright (C) 2001 Tassilo v. Parseval | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | # Version: $Id: Body.pm,v 1.14 2002/02/21 09:06:14 parkerpine Exp $ | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | package Mail::MboxParser::Mail::Body; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | require 5.004; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 20 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | ▶ | use vars qw($VERSION @EXPORT @ISA $AUTOLOAD $_HAVE_NOT_URI_FIND); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 20 | $VERSION = "0.15"; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 20 | @ISA = qw(Mail::MboxParser::Base Mail::MboxParser::Mail); | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 20 | ▶ | use overload '""' => sub { shift->as_string }, fallback => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 20 | eval { require URI::Find; }; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 20 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | $_HAVE_NOT_URI_FIND = 1; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 22 | ▶ | sub init(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 22 | my ($self, $ent, $bound, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 22 | $self->{CONTENT} = $ent->body; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 22 | $self->{BOUNDARY} = $bound; # the one in Content-type | |||||||||||||||||||||||||||||||||||||||||
| 36 | 22 | $self->{ARGS} = $conf; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 22 | ▶ | $self->{ARGS}->{decode} ||= 'NEVER'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"ARGS"}{"decode"} ||= "NEVER"
MC/DC0%0/1
$self->{"ARGS"}{"decode"} ||= "NEVER"
$self->{"ARGS"}{"decode"}
Truth table50%1/2
A
A= $self->{"ARGS"}{"decode"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | $self->_make_decoder($ent->head->mime_encoding) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | ▶ | if $self->{ARGS}->{decode} =~ /BODY|ALL/;; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub _make_decoder { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_decoder: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($self, $enc) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($enc eq 'base64') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return $self->{DECODER} = sub { MIME::Base64::decode_base64(shift) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($enc eq 'quoted-printable') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | require MIME::QuotedPrint; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | return $self->{DECODER} = sub { MIME::QuotedPrint::decode_qp(shift) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $self->{DECODER} = sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=4 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | $self->reset_last; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | return join "", $self->as_lines(strip_sig => 1) if $args{strip_sig}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my $decode = $self->{ARGS}->{decode}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | if ($decode eq 'BODY' || $decode eq 'ALL') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$decode eq "BODY" or $decode eq "ALL"
MC/DC0%0/2
$decode eq "BODY" or $decode eq "ALL"
$decode eq "BODY"
$decode eq "ALL"
Truth table33%1/3
A or B
A= $decode eq "BODY"B= $decode eq "ALL"
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return join "", map { $self->{DECODER}->($_) } @{$self->{CONTENT}}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | return join "", @{$self->{CONTENT}}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub as_lines() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_lines: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->reset_last; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $decode = $self->{ARGS}->{decode}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($decode eq 'BODY' || $decode eq 'ALL') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$decode eq "BODY" or $decode eq "ALL"
MC/DC0%0/2
$decode eq "BODY" or $decode eq "ALL"
$decode eq "BODY"
$decode eq "ALL"
Truth table0%0/3
A or B
A= $decode eq "BODY"B= $decode eq "ALL"
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return map { $self->{DECODER}->($_) } @{$self->{CONTENT}}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return @{$self->{CONTENT}} if ! $args{strip_sig}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | for (@{ $self->{CONTENT} }) { | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | last if /^--\040?[\r\n]?$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | push @lines, $_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | sub signature() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature: called CC=13 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 18 | $self->reset_last; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 18 | my $decode = $self->{ARGS}->{decode}; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 18 | my $bound = $self->{BOUNDARY}; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 18 | my @signature; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 18 | my $seperator = 0; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 18 | for (@{$self->{CONTENT}}) { | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # we are still outside the signature | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 560 | ▶ | if (! /^--\040?[\r\n]?$/ && not $seperator) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
/^--\040?[\r\n]?$/ || $seperator
MC/DC100%2/2
/^--\040?[\r\n]?$/ || $seperator
/^--\040?[\r\n]?$/
$seperator
Truth table100%3/3
A || B
A= /^--\040?[\r\n]?$/B= $seperator
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 532 | next; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # we hit the signature delimiter (--) | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | elsif (not $seperator) { $seperator = 1; next } | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 22 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # we are inside signature: is line perhaps MIME-boundary? | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 22 | ▶ | last if $bound && /^--\Q$bound\E/ && $seperator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$bound and /^--\Q$bound\E/ and $seperator
$bound and /^--\Q$bound\E/
MC/DC0%0/3
$bound and /^--\Q$bound\E/ and $seperator
$bound
/^--\Q$bound\E/
$seperator
Truth table25%1/4
A and B and C
A= $boundB= /^--\Q$bound\E/C= $seperator
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # none of the above => signature line | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 22 | push @signature, $_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 18 | ▶ | $self->{LAST_ERR} = "No signature found" if !@signature; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 18 | ▶ | if ($decode eq 'BODY' || $decode eq 'ALL') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$decode eq "BODY" or $decode eq "ALL"
MC/DC0%0/2
$decode eq "BODY" or $decode eq "ALL"
$decode eq "BODY"
$decode eq "ALL"
Truth table33%1/3
A or B
A= $decode eq "BODY"B= $decode eq "ALL"
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $_ = $self->{DECODER}->($_) for @signature; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 18 | ▶ | return @signature if $seperator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub extract_urls(@) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_urls: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->reset_last; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $args{unique} = 0 if not exists $args{unique}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($_HAVE_NOT_URI_FIND) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | carp <<EOW; | |||||||||||||||||||||||||||||||||||||||||
| 132 | You need the URI::Find module in order to use extract_urls. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | EOW | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my @uris; my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | for my $line (@{$self->{CONTENT}}) { | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | URI::Find::find_uris($line, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my (undef, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $line =~ s/^\s+|\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if (not $seen{$url}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | push @uris, { url => $url, context => $line }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | $seen{$url}++ if $args{unique}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | $self->{LAST_ERR} = "No URLs found" if @uris == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return @uris; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub quotes() { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quotes: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $decode = $self->{ARGS}->{decode}; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $self->reset_last; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my %ret; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $q = 0; # num of '>' | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $in = 0; # being inside a quote | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $last = 0; # num of quotes in last line | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | for (@{$self->{CONTENT}}) { | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if ($decode eq 'ALL' || $decode eq 'BODY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$decode eq "ALL" or $decode eq "BODY"
MC/DC0%0/2
$decode eq "ALL" or $decode eq "BODY"
$decode eq "ALL"
$decode eq "BODY"
Truth table0%0/3
A or B
A= $decode eq "ALL"B= $decode eq "BODY"
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $_ = $self->{DECODER}->($_); | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # count quotation signs | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $q = 0; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $t = "a" x length; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | for my $c (unpack $t, $_) { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($c eq '>') { $q++ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($c ne '>' && $c ne ' ') { last } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c ne ">" and $c ne " "
MC/DC0%0/2
$c ne ">" and $c ne " "
$c ne ">"
$c ne " "
Truth table0%0/3
A and B
A= $c ne ">"B= $c ne " "
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # first: create a hash-element for level $q | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (! exists $ret{$q}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $ret{$q} = []; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # if last line had the same level as current one: | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # attach the line to the last one | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if ($last == $q) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if (@{$ret{$q}} == 0) { $ret{$q}->[$q] .= $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | else { $ret{$q}->[-1] .= $_ } | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # if not: | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # create a new array-element in the appropriate hash-element | ||||||||||||||||||||||||||||||||||||||||||
| 194 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | push @{$ret{$q}}, $_; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $last = $q; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return \%ret; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||||||