| 1 | package Net::Google::Calendar::WebContent; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | $Net::Google::Calendar::WebContent::VERSION = '1.05'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use XML::Atom; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use XML::Atom::Link; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | #use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | #use XML::Atom::Namespace; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use base qw(XML::Atom::Link Net::Google::Calendar::Base); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | unshift @ISA, 'XML::Atom::Link'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my $ns = XML::Atom::Namespace->new( | |||||||||||||||||||||||||||||||||||||||||
| 15 | gCal => 'http://schemas.google.com/gCal/2005' | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | Net::Google::Calendar::WebContent - handle web content | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | Web content can be images ... | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | my $content = Net::Google::Calendar::WebContent->new( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | title => 'World Cup', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | href => 'http://www.google.com/calendar/images/google-holiday.gif', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | web_content => { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | url => "http://www.google.com/logos/worldcup06.gif" | ||||||||||||||||||||||||||||||||||||||||||
| 32 | width => 276, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | height => 120, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | type => 'image/gif', | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | $entry->add_link($content); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | or html ... | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | my $content = Net::Google::Calendar::WebContent->new( | ||||||||||||||||||||||||||||||||||||||||||
| 42 | title => 'Embedded HTML', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | href => 'http://www.example.com/favico.icon', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | web_content => { | ||||||||||||||||||||||||||||||||||||||||||
| 45 | url => "http://www.example.com/some.html" | ||||||||||||||||||||||||||||||||||||||||||
| 46 | width => 276, | ||||||||||||||||||||||||||||||||||||||||||
| 47 | height => 120, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | type => 'text/html', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | $entry->add_link($content); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | or special Google Gadgets (http://www.google.com/ig/directory) | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | my $content = Net::Google::Calendar::WebContent->new( | ||||||||||||||||||||||||||||||||||||||||||
| 57 | title => 'DateTime Gadget (a classic!)', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | href => 'http://www.google.com/favicon.ico', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | web_content => { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | url => 'http://google.com/ig/modules/datetime.xml', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | width => 300, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | height => 136, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | type => 'application/x-google-gadgets+xml', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | or | ||||||||||||||||||||||||||||||||||||||||||
| 69 | my $content = Net::Google::Calendar::WebContent->new( | ||||||||||||||||||||||||||||||||||||||||||
| 70 | title => 'Word of the Day', | ||||||||||||||||||||||||||||||||||||||||||
| 71 | href => 'http://www.thefreedictionary.com/favicon.ico', | ||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 73 | $content->web_content( | ||||||||||||||||||||||||||||||||||||||||||
| 74 | url => 'http://www.thefreedictionary.com/_/WoD/wod-module.xml', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | width => 300, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | height => 136, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | type => 'application/x-google-gadgets+xml', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | prefs => { Days => 1, Format => 0 }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | (note the ability to set webContentGadgetPrefs using the special prefs attribute). | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =head2 new [opt[s]] | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Options can be | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =item title | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | The title of the web content | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =item href | ||||||||||||||||||||||||||||||||||||||||||
| 96 | A url of an icon to use | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =item type | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | The mime type of content. Can be either C<text/html> C<image/*> or C<application/x-google-gadgets+xml> | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | Not needed for C<text/html>. | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =item web_content | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | The actual web content. This just gets passed to the C<web_content()> method. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | #my $self = XML::Atom::Link->new(Version => "1.0"); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | #$self = bless $self, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $ns = XML::Atom::Namespace->new(gd => 'http://schemas.google.com/g/2005'); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $self = $class->SUPER::new(Version => "1.0", ); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->{_gd_ns} = $ns; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->rel('http://schemas.google.com/gCal/2005/webContent'); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | for my $field (qw(title href)) { | |||||||||||||||||||||||||||||||||||||||||
| 124 | die "You must pass in the field '$field' to a WebContent link\n" | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | unless defined $params{$field}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->$field($params{$field}); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $type = $params{type}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | #die "You must pass a type" unless defined $type; | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | $self->_set_type($type) if defined $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($params{web_content}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->web_content(%{$params{web_content}}); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # h-h-hack | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | $self->web_content(empty => 1); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub _set_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_type: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | unless ($type eq 'text/html' or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$type eq "text/html" or $type eq "application/x-google-gadgets+xml" or $type =~ m[^image/]
$type eq "text/html" or $type eq "application/x-google-gadgets+xml"
MC/DC0%0/3
$type eq "text/html" or $type eq "application/x-google-gadgets+xml" or $type =~ m[^image/]
$type eq "text/html"
$type eq "application/x-google-gadgets+xml"
$type =~ m[^image/]
Truth table0%0/4
A or B or C
A= $type eq "text/html"B= $type eq "application/x-google-gadgets+xml"C= $type =~ m[^image/]
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | $type eq 'application/x-google-gadgets+xml' or | ||||||||||||||||||||||||||||||||||||||||||
| 146 | $type =~ m!^image/!) { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | die "The type param must be text/html or application/x-google-gadgets+xml or image/*\n"; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $self->type($type); | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =head2 web_content [param[s]] | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | Takes a hash of parameters. Valid are | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =item url | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | The url of the content. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | =item width | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | The width of the content. | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | =item height | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | The height of the content. | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | =item type | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | The mime-type (see above) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | =item prefs | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | This takes a hash ref and all pairs are turned into C<webContentGadgetPref> entries. | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub web_content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
web_content: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $name = 'gCal:webContent'; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | # h-h-hack | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | %params = () if $params{empty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | if (my $type = delete $params{type}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->_set_type($type); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # egregious hack | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $params{'xmlns:gd'} = 'http://schemas.google.com/g/2005'; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $params{'xmlns:gCal'} = 'http://schemas.google.com/gCal/2005'; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $prefs = delete $params{prefs}; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | XML::Atom::Base::set($self, '', $name, '', \%params); | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $content = $self->_my_get('', $name); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | foreach my $key (keys %{$prefs}) { | |||||||||||||||||||||||||||||||||||||||||
| 200 | # TODO: this feels icky | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $node; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | if (LIBXML) { | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $node = XML::LibXML::Element->new($name.'GadgetPref'); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $node->setAttribute( name => $key ); | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | $node->setAttribute( value => $prefs->{$key} ); | |||||||||||||||||||||||||||||||||||||||||
| 206 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | $node = XML::XPath::Node::Element->new($name.'GadgetPref'); | ||||||||||||||||||||||||||||||||||||||||||
| 208 | $node->addAttribute(XML::XPath::Node::Attribute->new(name => $key)); | ||||||||||||||||||||||||||||||||||||||||||
| 209 | $node->addAttribute(XML::XPath::Node::Attribute->new(value => $prefs->{key})); | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $content->appendChild($node); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return $self->_my_get('', $name); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||