| 1 | package XML::Generator::RSS10::cc; | ||
| 2 | { | ||
| 3 | $XML::Generator::RSS10::cc::VERSION = '0.02'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | |||
| 8 | use base 'XML::Generator::RSS10::Module'; | ||
| 9 | |||
| 10 | use Params::Validate qw( validate SCALAR ); | ||
| 11 | |||
| 12 | sub NamespaceURI { 'http://web.resource.org/cc/' } | ||
| 13 | |||
| 14 | use constant CONTENTS_SPEC => { | ||
| 15 | license => { type => SCALAR }, | ||
| 16 | }; | ||
| 17 | |||
| 18 | my %Licenses = ( | ||
| 19 | 'http://creativecommons.org/licenses/by/2.0/' => { | ||
| 20 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 21 | requires => [qw( Attribution Notice )], | ||
| 22 | }, | ||
| 23 | |||
| 24 | 'http://creativecommons.org/licenses/by-nd/2.0/' => { | ||
| 25 | permits => [qw( Reproduction Distribution )], | ||
| 26 | requires => [qw( Attribution Notice )], | ||
| 27 | }, | ||
| 28 | |||
| 29 | 'http://creativecommons.org/licenses/by-nc-nd/2.0/' => { | ||
| 30 | permits => [qw( Reproduction Distribution )], | ||
| 31 | requires => [qw( Attribution Notice )], | ||
| 32 | prohibits => ['CommercialUse'], | ||
| 33 | }, | ||
| 34 | |||
| 35 | 'http://creativecommons.org/licenses/by-nc/2.0/' => { | ||
| 36 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 37 | requires => [qw( Attribution Notice )], | ||
| 38 | prohibits => ['CommercialUse'], | ||
| 39 | }, | ||
| 40 | |||
| 41 | 'http://creativecommons.org/licenses/by-nc-sa/2.0/' => { | ||
| 42 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 43 | requires => [qw( Attribution Notice ShareAlike )], | ||
| 44 | prohibits => ['CommercialUse'], | ||
| 45 | }, | ||
| 46 | |||
| 47 | 'http://creativecommons.org/licenses/by-sa/2.0/' => { | ||
| 48 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 49 | requires => [qw( Attribution Notice ShareAlike )], | ||
| 50 | }, | ||
| 51 | |||
| 52 | 'http://creativecommons.org/licenses/by/3.0/us/' => { | ||
| 53 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 54 | requires => [qw( Attribution Notice )], | ||
| 55 | }, | ||
| 56 | |||
| 57 | 'http://creativecommons.org/licenses/by-nd/3.0/us/' => { | ||
| 58 | permits => [qw( Reproduction Distribution )], | ||
| 59 | requires => [qw( Attribution Notice )], | ||
| 60 | }, | ||
| 61 | |||
| 62 | 'http://creativecommons.org/licenses/by-nc-nd/3.0/us/' => { | ||
| 63 | permits => [qw( Reproduction Distribution )], | ||
| 64 | requires => [qw( Attribution Notice )], | ||
| 65 | prohibits => ['CommercialUse'], | ||
| 66 | }, | ||
| 67 | |||
| 68 | 'http://creativecommons.org/licenses/by-nc/3.0/us/' => { | ||
| 69 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 70 | requires => [qw( Attribution Notice )], | ||
| 71 | prohibits => ['CommercialUse'], | ||
| 72 | }, | ||
| 73 | |||
| 74 | 'http://creativecommons.org/licenses/by-nc-sa/3.0/us/' => { | ||
| 75 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 76 | requires => [qw( Attribution Notice ShareAlike )], | ||
| 77 | prohibits => ['CommercialUse'], | ||
| 78 | }, | ||
| 79 | |||
| 80 | 'http://creativecommons.org/licenses/by-sa/3.0/us/' => { | ||
| 81 | permits => [qw( Reproduction Distribution DerivativeWorks )], | ||
| 82 | requires => [qw( Attribution Notice ShareAlike )], | ||
| 83 | }, | ||
| 84 | ); | ||
| 85 | |||
| 86 | sub contents { | ||
| 87 | my $class = shift; | ||
| 88 | my $rss = shift; | ||
| 89 | my %p = validate( @_, CONTENTS_SPEC ); | ||
| 90 | |||
| 91 | if ( exists $p{license} ) { | ||
| 92 | die "Unknown license: $p{license}\n" | ||
| 93 | unless exists $Licenses{ $p{license} }; | ||
| 94 | |||
| 95 | $rss->_element( 'cc', 'license', [ 'rdf', 'about', $p{license} ] ); | ||
| 96 | $rss->_newline_if_pretty; | ||
| 97 | |||
| 98 | $rss->{__cc_licenses__}{ $p{license} } = 1; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | sub channel_hook { | ||
| 103 | my $class = shift; | ||
| 104 | my $rss = shift; | ||
| 105 | |||
| 106 | foreach my $license ( keys %{ $rss->{__cc_licenses__} } ) { | ||
| 107 | $rss->_start_element( | ||
| 108 | 'cc', 'License', | ||
| 109 | [ 'rdf', 'about', $license ], | ||
| 110 | ); | ||
| 111 | $rss->_newline_if_pretty; | ||
| 112 | |||
| 113 | foreach my $elt ( keys %{ $Licenses{$license} } ) { | ||
| 114 | foreach my $val ( @{ $Licenses{$license}{$elt} } ) { | ||
| 115 | $rss->_element( | ||
| 116 | 'cc', $elt, | ||
| 117 | [ 'rdf', 'resource', "http://web.resource.org/cc/$val" ], | ||
| 118 | ); | ||
| 119 | $rss->_newline_if_pretty; | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | $rss->_end_element( 'cc', 'License' ); | ||
| 124 | $rss->_newline_if_pretty; | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | 1; | ||
| 129 | |||
| 130 | # ABSTRACT: Support for the Creative Commons (cc) RSS 1.0 module | ||
| 131 | |||
| 132 | |||
| 133 | |||
| 134 | =pod | ||
| 135 | |||
| 136 | =head1 NAME | ||
| 137 | |||
| 138 | XML::Generator::RSS10::cc - Support for the Creative Commons (cc) RSS 1.0 module | ||
| 139 | |||
| 140 | =head1 VERSION | ||
| 141 | |||
| 142 | version 0.02 | ||
| 143 | |||
| 144 | =head1 SYNOPSIS | ||
| 145 | |||
| 146 | use XML::Generator::RSS10; | ||
| 147 | |||
| 148 | my $rss = XML::Generator::RSS10->new( Handler => $sax_handler ); | ||
| 149 | |||
| 150 | $rss->item( title => 'Exciting News About my Pants!', | ||
| 151 | link => 'http://pants.example.com/my/news.html', | ||
| 152 | description => 'My pants are full of ants!', | ||
| 153 | cc => { license => 'http://creativecommons.org/licenses/by/3.0/us/' } | ||
| 154 | ); | ||
| 155 | |||
| 156 | $rss->channel( title => 'Pants', | ||
| 157 | link => 'http://pants.example.com/', | ||
| 158 | description => 'A fascinating pants site', | ||
| 159 | ); | ||
| 160 | |||
| 161 | =head1 DESCRIPTION | ||
| 162 | |||
| 163 | This module provides support for the Creative Commons (cc) RSS 1.0 module. | ||
| 164 | |||
| 165 | =head1 PARAMETERS | ||
| 166 | |||
| 167 | This module allows expects one parameter, "license", which can be | ||
| 168 | passed to any method. It will automatically add channel subelements | ||
| 169 | for each license used. | ||
| 170 | |||
| 171 | =head1 AUTHOR | ||
| 172 | |||
| 173 | Dave Rolsky <autarch@urth.org> | ||
| 174 | |||
| 175 | =head1 COPYRIGHT AND LICENSE | ||
| 176 | |||
| 177 | This software is Copyright (c) 2011 by Dave Rolsky. | ||
| 178 | |||
| 179 | This is free software, licensed under: | ||
| 180 | |||
| 181 | The Artistic License 2.0 (GPL Compatible) | ||
| 182 | |||
| 183 | =cut | ||
| 184 | |||
| 185 | |||
| 186 | __END__ |