| 1 | package XML::Generator::RSS10::content; | ||
| 2 | { | ||
| 3 | $XML::Generator::RSS10::content::VERSION = '0.02'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | |||
| 8 | use base 'XML::Generator::RSS10::Module'; | ||
| 9 | |||
| 10 | use Params::Validate qw( validate SCALAR ARRAYREF ); | ||
| 11 | |||
| 12 | sub NamespaceURI { 'http://purl.org/rss/1.0/modules/content/' } | ||
| 13 | |||
| 14 | use constant CONTENTS_SPEC => { | ||
| 15 | encoded => { type => SCALAR, optional => 1 }, | ||
| 16 | items => { type => ARRAYREF, optional => 1 }, | ||
| 17 | }; | ||
| 18 | |||
| 19 | sub contents { | ||
| 20 | my $class = shift; | ||
| 21 | my $rss = shift; | ||
| 22 | my %p = validate( @_, CONTENTS_SPEC ); | ||
| 23 | |||
| 24 | if ( exists $p{encoding} ) { | ||
| 25 | $rss->_element( $class->Prefix, 'encoding', $p{encoding} ); | ||
| 26 | } | ||
| 27 | |||
| 28 | if ( exists $p{encoded} ) { | ||
| 29 | $rss->_element_with_cdata( 'content', 'encoded', $p{encoded} ); | ||
| 30 | $rss->_newline_if_pretty; | ||
| 31 | } | ||
| 32 | |||
| 33 | if ( exists $p{items} ) { | ||
| 34 | $rss->_start_element( 'content', 'items' ); | ||
| 35 | $rss->_newline_if_pretty; | ||
| 36 | |||
| 37 | $rss->_start_element( 'rdf', 'Bag' ); | ||
| 38 | $rss->_newline_if_pretty; | ||
| 39 | |||
| 40 | foreach my $item ( @{ $p{items} } ) { | ||
| 41 | $class->_item( $rss, $item ); | ||
| 42 | } | ||
| 43 | |||
| 44 | $rss->_end_element( 'rdf', 'Bag' ); | ||
| 45 | $rss->_newline_if_pretty; | ||
| 46 | |||
| 47 | $rss->_end_element( 'content', 'items' ); | ||
| 48 | $rss->_newline_if_pretty; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | use constant _ITEM_SPEC => { | ||
| 53 | format => { type => SCALAR }, | ||
| 54 | encoding => { type => SCALAR, optional => 1 }, | ||
| 55 | content => { type => SCALAR, optional => 1 }, | ||
| 56 | about => { type => SCALAR, optional => 1 }, | ||
| 57 | }; | ||
| 58 | |||
| 59 | sub _item { | ||
| 60 | my $class = shift; | ||
| 61 | my $rss = shift; | ||
| 62 | my %p = validate( @_, _ITEM_SPEC ); | ||
| 63 | |||
| 64 | die | ||
| 65 | "Must provide either content or about parameter for a content module item.\n" | ||
| 66 | unless exists $p{about} || exists $p{content}; | ||
| 67 | |||
| 68 | $rss->_start_element( 'rdf', 'li' ); | ||
| 69 | $rss->_newline_if_pretty; | ||
| 70 | |||
| 71 | my @att = exists $p{about} ? ( 'rdf', 'about', $p{about} ) : (); | ||
| 72 | $rss->_start_element( 'content', 'item', \@att ); | ||
| 73 | $rss->_newline_if_pretty; | ||
| 74 | |||
| 75 | $rss->_element( | ||
| 76 | 'content', 'format', | ||
| 77 | [ 'rdf', 'resource', $p{format} ], | ||
| 78 | ); | ||
| 79 | $rss->_newline_if_pretty; | ||
| 80 | |||
| 81 | if ( exists $p{encoding} ) { | ||
| 82 | $rss->_element( | ||
| 83 | 'content', 'encoding', | ||
| 84 | [ 'rdf', 'resource', $p{encoding} ], | ||
| 85 | ); | ||
| 86 | $rss->_newline_if_pretty; | ||
| 87 | } | ||
| 88 | |||
| 89 | if ( exists $p{content} ) { | ||
| 90 | $rss->_element_with_cdata( 'rdf', 'value', $p{content} ); | ||
| 91 | $rss->_newline_if_pretty; | ||
| 92 | } | ||
| 93 | |||
| 94 | $rss->_end_element( 'content', 'item' ); | ||
| 95 | $rss->_newline_if_pretty; | ||
| 96 | |||
| 97 | $rss->_end_element( 'rdf', 'li' ); | ||
| 98 | $rss->_newline_if_pretty; | ||
| 99 | } | ||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | # ABSTRACT: Support for the Dublin Core (dc) RSS 1.0 module | ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | =pod | ||
| 108 | |||
| 109 | =head1 NAME | ||
| 110 | |||
| 111 | XML::Generator::RSS10::content - Support for the Dublin Core (dc) RSS 1.0 module | ||
| 112 | |||
| 113 | =head1 VERSION | ||
| 114 | |||
| 115 | version 0.02 | ||
| 116 | |||
| 117 | =head1 SYNOPSIS | ||
| 118 | |||
| 119 | use XML::Generator::RSS10; | ||
| 120 | |||
| 121 | my $rss = XML::Generator::RSS10->new( Handler => $sax_handler ); | ||
| 122 | |||
| 123 | $rss->channel( title => 'Pants', | ||
| 124 | link => 'http://pants.example.com/', | ||
| 125 | description => 'A fascinating pants site', | ||
| 126 | content => | ||
| 127 | { items => | ||
| 128 | [ { format => 'http://www.w3.org/1999/xhtml', | ||
| 129 | content => '<b>Axis</b> Love', | ||
| 130 | }, | ||
| 131 | { format => 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional', | ||
| 132 | about => 'http://example.com/content-elsewhere', | ||
| 133 | }, | ||
| 134 | { format => 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional', | ||
| 135 | encoding => 'http://www.w3.org/TR/REC-xml#dt-wellformed', | ||
| 136 | content => '<i>italics</i>', | ||
| 137 | }, | ||
| 138 | ], | ||
| 139 | }, | ||
| 140 | ); | ||
| 141 | |||
| 142 | =head1 DESCRIPTION | ||
| 143 | |||
| 144 | This module provides support for the Content (content) RSS 1.0 module. | ||
| 145 | |||
| 146 | =head1 PARAMETERS | ||
| 147 | |||
| 148 | This module expects to receive a single parameter, "items". This | ||
| 149 | parameter should be an arrayref of hash references. Each of these | ||
| 150 | hash references should contain a single item's content. | ||
| 151 | |||
| 152 | The hash references may contain the following parameters: | ||
| 153 | |||
| 154 | =over 4 | ||
| 155 | |||
| 156 | =item * format | ||
| 157 | |||
| 158 | The value for the C<content:format> element. Required. | ||
| 159 | |||
| 160 | =item * about | ||
| 161 | |||
| 162 | If this is given, then this key's value will be used for the | ||
| 163 | C<content:item> element's C<rdf:resource> attribute. One of this key | ||
| 164 | or the "content" key is required. | ||
| 165 | |||
| 166 | =item * content | ||
| 167 | |||
| 168 | The content for the item. One of this key or the "about" key is | ||
| 169 | required. | ||
| 170 | |||
| 171 | =item * encoding | ||
| 172 | |||
| 173 | If the content is well-formed XML, then this should be included, with | ||
| 174 | the value "http://www.w3.org/TR/REC-xml#dt-wellformed". | ||
| 175 | |||
| 176 | =back | ||
| 177 | |||
| 178 | =head1 AUTHOR | ||
| 179 | |||
| 180 | Dave Rolsky <autarch@urth.org> | ||
| 181 | |||
| 182 | =head1 COPYRIGHT AND LICENSE | ||
| 183 | |||
| 184 | This software is Copyright (c) 2011 by Dave Rolsky. | ||
| 185 | |||
| 186 | This is free software, licensed under: | ||
| 187 | |||
| 188 | The Artistic License 2.0 (GPL Compatible) | ||
| 189 | |||
| 190 | =cut | ||
| 191 | |||
| 192 | |||
| 193 | __END__ |