| | 105 | sub new_with_comment { |
| | 106 | my $class = shift; |
| | 107 | my ( $comment, %param ) = @_; |
| | 108 | my $rfc_compat = $param{Version} && $param{Version} eq '1'; |
| | 109 | |
| | 110 | my $entry = $comment->entry; |
| | 111 | return unless $entry; |
| | 112 | my $blog = $comment->blog; |
| | 113 | return unless $blog; |
| | 114 | |
| | 115 | my $atom = $class->new(%param); |
| | 116 | $atom->title(encode_text($entry->title, undef, 'utf-8')); |
| | 117 | $atom->content(encode_text($comment->text, undef, 'utf-8')); |
| | 118 | # Old Atom API gets application/xhtml+xml for compatibility -- but why |
| | 119 | # do we say it's that when all we're guaranteed is it's an opaque blob |
| | 120 | # of text? So use 'html' for new RFC compatible output. |
| | 121 | # XML::Atom::Content intelligently determines content-type for rfc compat. |
| | 122 | unless ( $rfc_compat ) { |
| | 123 | $atom->content->type('application/xhtml+xml'); |
| | 124 | } |
| | 125 | |
| | 126 | my $atom_author = new XML::Atom::Person(%param); |
| | 127 | $atom_author->name(encode_text($comment->author, undef, 'utf-8')); |
| | 128 | $atom_author->email($comment->email) if $comment->email; |
| | 129 | my $author_url_field = $rfc_compat ? 'uri' : 'url'; |
| | 130 | $atom_author->$author_url_field($comment->url) if $comment->url; |
| | 131 | $atom->author($atom_author); |
| | 132 | |
| | 133 | my $co = _create_issued($comment->created_on, $blog); |
| | 134 | $atom->issued($co); |
| | 135 | my $upd = $comment->modified_on; |
| | 136 | if ( $upd ) { |
| | 137 | $atom->updated( _create_issued( $upd, $blog ) ); |
| | 138 | } |
| | 139 | else { |
| | 140 | $atom->updated( $co ); |
| | 141 | } |
| | 142 | $atom->add_link({ rel => 'alternate', type => 'text/html', |
| | 143 | href => $entry->archive_url . '#comment-' . $comment->id }); |
| | 144 | my ($host) = $blog->site_url =~ m!^https?://([^/:]+)(:\d+)?/!; |
| | 145 | |
| | 146 | $atom->id($entry->atom_id . '/' . $comment->id); |
| | 147 | $atom; |
| | 148 | } |
| | 149 | |