I'm getting data to fill out an e-mail template, and I'm wondering if this method is too long. How could I refactor it?
sub getEmailData
{
my $self = shift;
my $defs = QuickContentFunction::Simple::QuerySearchFieldDefinitions->new();
my $phParams = decode_json($self->parameters);
my @aFields = split(/~/, $phParams->{sFields});
my @aCategories = split(/~/, $phParams->{sCategories});
my @aValues = split(/~/, $phParams->{sValues});
my @aConditions = split(/~/, $phParams->{sConditions});
my $sSummary = $phParams->{sSummary};
$sSummary =~ s/\'//g;
my @aSummary = split(/\d/, $sSummary);
my $phData = { name => $self->name };
my $mapping = $self->getOperatorMapping();
for (my $i = 0; $i < scalar(@aFields); $i++) {
my $phFieldInfo = $defs->getFieldHash( $aCategories[$i], $aFields[$i]);
my $value = $aValues[$i];
if ($phFieldInfo->{value_displays}) {
$value = @{$phFieldInfo->{value_displays}}[$value];
} elsif ($phFieldInfo->{value_keys}) {
$value = @{$phFieldInfo->{value_keys}}[$value];
}
push( @{$phData->{conditions}}, {
field => $phFieldInfo->{field_display},
operator => $mapping->{$phFieldInfo->{field_type}}->{$aConditions[$i]},
value => $value,
postfix => $aSummary[$i+1] || undef
} );
}
$phData->{mode} = lc($phParams->{sMode});
if ($self->hasResults()) {
$phData->{deals} = \@{decode_json($self->result)};
}
return $phData;
}