Skip to content

Commit

Permalink
Split methods to reduce complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Oct 10, 2018
1 parent 0104696 commit d2b8f67
Showing 1 changed file with 45 additions and 33 deletions.
78 changes: 45 additions & 33 deletions lib/XML/Feed/Entry/Format/Atom.pm
Expand Up @@ -72,46 +72,58 @@ my %types = (
sub content {
my $entry = shift;
if (@_) {
my %param;
my $base;
my $orig_body;
if (ref($_[0]) eq 'XML::Feed::Content') {
$orig_body = $_[0]->body;
if (defined $_[0]->type && defined $types{$_[0]->type}) {
%param = (Body => $orig_body, Type => $types{$_[0]->type});

if ($param{'Type'} eq "html") {
$param{'Body'} = HTML::Entities::encode_entities($param{'Body'});
}
} else {
return $entry->set_content(@_);
} else {
return $entry->get_content;
}
}

sub set_content {
my $entry = shift;

my %param;
my $base;
my $orig_body;
if (ref($_[0]) eq 'XML::Feed::Content') {
$orig_body = $_[0]->body;
if (defined $_[0]->type && defined $types{$_[0]->type}) {
%param = (Body => $orig_body, Type => $types{$_[0]->type});

if ($param{'Type'} eq "html") {
$param{'Body'} = HTML::Entities::encode_entities($param{'Body'});
}
$base = $_[0]->base if defined $_[0]->base;
} else {
$orig_body = $_[0];
}
if (!exists($param{Body}))
{
$param{Body} = $orig_body;
}
$entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
# Assigning again so the type will be normalized. This seems to be
# an XML-Atom do-what-I-don't-meannery.
$entry->{entry}->content->body($orig_body);
$entry->{entry}->content->base($base) if defined $base;
$base = $_[0]->base if defined $_[0]->base;
} else {
my $c = $entry->{entry}->content;
$orig_body = $_[0];
}
if (!exists($param{Body}))
{
$param{Body} = $orig_body;
}
$entry->{entry}->content(XML::Atom::Content->new(%param, Version => 1.0));
# Assigning again so the type will be normalized. This seems to be
# an XML-Atom do-what-I-don't-meannery.
$entry->{entry}->content->body($orig_body);
$entry->{entry}->content->base($base) if defined $base;
}

# map Atom types to MIME types
my $type = $c ? $c->type : undef;
if ($type) {
$type = 'text/html' if $type eq 'xhtml' || $type eq 'html';
$type = 'text/plain' if $type eq 'text';
}
sub get_content {
my $entry = shift;

XML::Feed::Content->wrap({ type => $type,
base => $c ? $c->base : undef,
body => $c ? $c->body : undef });
my $c = $entry->{entry}->content;

# map Atom types to MIME types
my $type = $c ? $c->type : undef;
if ($type) {
$type = 'text/html' if $type eq 'xhtml' || $type eq 'html';
$type = 'text/plain' if $type eq 'text';
}

XML::Feed::Content->wrap({ type => $type,
base => $c ? $c->base : undef,
body => $c ? $c->body : undef });
}

sub category {
Expand Down

0 comments on commit d2b8f67

Please sign in to comment.