Another round of changes to fix (and test) https://rt.cpan.org/Public/Bug/Display...
[catagits/XML-Feed.git] / lib / XML / Feed / Format / Atom.pm
index b0a8554..634606f 100644 (file)
@@ -162,34 +162,34 @@ sub link {
 sub summary {
     my $entry = shift;
     if (@_) {
-               my %param;
-               if (ref($_[0]) eq 'XML::Feed::Content') {
-                       %param = (Body => $_[0]->body);
-               } else {
-                        %param = (Body => $_[0]);
-               }
-               $entry->{entry}->summary(XML::Atom::Content->new(%param, Version => 1.0));
+        my %param;
+        if (ref($_[0]) eq 'XML::Feed::Content') {
+            %param = (Body => $_[0]->body);
+        } else {
+            %param = (Body => $_[0]);
+        }
+        $entry->{entry}->summary(XML::Atom::Content->new(%param, Version => 1.0));
     } else {
-               my $s = $entry->{entry}->summary;
+        my $s = $entry->{entry}->summary;
         # map Atom types to MIME types
         my $type = ($s && ref($s) eq 'XML::Feed::Content') ? $s->type : undef;
         if ($type) {
             $type = 'text/html'  if $type eq 'xhtml' || $type eq 'html';
             $type = 'text/plain' if $type eq 'text';
         }
-               my $body = $s;  
-               if (defined $s && ref($s) eq 'XML::Feed::Content') {
-                       $body = $s->body;
-               }
+        my $body = $s;
+        if (defined $s && ref($s) eq 'XML::Feed::Content') {
+            $body = $s->body;
+        }
         XML::Feed::Content->wrap({ type => $type,
                                    body => $body });
     }
 }
 
 my %types = (
-       'text/xhtml' => 'xhtml',
-       'text/html'  => 'html',
-       'text/plain' => 'text',
+    'text/xhtml' => 'xhtml',
+    'text/html'  => 'html',
+    'text/plain' => 'text',
 );
 
 sub content {
@@ -203,21 +203,23 @@ sub content {
             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});
+                if ($param{'Type'} eq "html") {
+                    $param{'Body'} = HTML::Entities::encode_entities($param{'Body'});
                 }
             } else {
-                # %param = (Body => $_[0]->body);
             }
             $base = $_[0]->base if defined $_[0]->base;
         } else {
             $orig_body = $_[0];
-            # %param = (Body => $_[0]);
         }
-        if (!exists $param{Body}) {
+        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;
     } else {
         my $c = $entry->{entry}->content;