Subject: | Feedback from XML::Atom::Service |
Hi,
I'm sending three patches, which are currently implemented in
XML::Atom::Service. The patches are independent each other, and you can
choose any of them. Please update XML::Atom if you find them useful.
New AtomPub elements are implemented in XML::Atom::Service because of
historical reasons, even if some of them are defined in Feed/Entry
Documents. But now, it's better to be moved to XML::Atom, since AtomPub
specification has been fixed as RFC 5023.
# namespace of atom:category can't be moved to XML::Atom as I said last
week, but it's trivial issue and you can ignore it ;-)
* XML-Atom-0.27_01-atompub.patch
defines new AtomPub elements/attributes in Entry Document, that are
content/@src, app:edited, app:control, and app:draft.
* XML-Atom-0.27_01-smart_link.patch
defines some relation oriented link methods, like:
$entry->alternate_link('http://www.example.com/blog/1.html');
print $entry->alternate_link; # 'http://www.example.com/blog/1.html'
Though this patch is not for AtomPub, I think it's useful.
* XML-Atom-0.27_01-mk_elem_list_accessor.patch
introduces a new method named "mk_elem_list_accessor", by which you can
easily define an accessor to text elements, multiple which there can be.
In the current XML::Atom implementation, it is not easy to make an
accessor to app:accept element. This is the reason why I introduced
this method in XML::Atom::Service.
<collection>
<accept>image/jpeg</accept>
<accept>image/png</accept>
<accept>image/gif</accept>
</collection>
Regards,
Subject: | XML-Atom-0.27_01-mk_elem_list_accessor.patch |
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Base.pm XML-Atom-0.27_01-mk_elem_list_accessor/lib/XML/Atom/Base.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Base.pm 2007-10-04 22:07:39.000000000 +0900
+++ XML-Atom-0.27_01-mk_elem_list_accessor/lib/XML/Atom/Base.pm 2007-10-14 12:09:43.000000000 +0900
@@ -338,6 +338,59 @@
};
}
+# accessors to text elements, multiple which there can be
+sub mk_elem_list_accessor {
+ my $class = shift;
+ my($name, $moniker) = @_;
+
+ no strict 'refs'; ## no critic
+
+ *{"$class\::$name"} = sub {
+ my $obj = shift;
+
+ my $ns_uri = $class->element_ns || $obj->ns;
+ if (@_) {
+ # setter: clear existent elements first
+ my @elem = childlist($obj->elem, $ns_uri, $name);
+ for my $el (@elem) {
+ $obj->elem->removeChild($el);
+ }
+
+ # add the new elements for each
+ my $adder = "add_$name";
+ for my $add_elem (@_) {
+ $obj->$adder($add_elem);
+ }
+ } else {
+ # getter:
+ my @children = map { $_->textContent } childlist( $obj->elem, $ns_uri, $name );
+ wantarray ? @children : $children[0];
+ }
+ };
+
+ if ($moniker) {
+ *{"$class\::$moniker"} = sub {
+ my $obj = shift;
+ if (@_) {
+ return $obj->$name(@_);
+ } else {
+ my @obj = $obj->$name;
+ return wantarray ? @obj : \@obj;
+ }
+ };
+ }
+
+ *{"$class\::add_$name"} = sub {
+ my $obj = shift;
+ my($stuff) = @_;
+
+ my $ns_uri = $class->element_ns || $obj->ns;
+ my $elem = create_element( $ns_uri, 'accept' );
+ $elem->appendText($stuff);
+ $obj->elem->appendChild($elem);
+ };
+}
+
sub as_xml {
my $obj = shift;
if (LIBXML) {
Only in XML-Atom-0.27_01-mk_elem_list_accessor/lib/XML/Atom: Base.pm~
Subject: | XML-Atom-0.27_01-smart_link.patch |
Only in XML-Atom-0.27_01: Makefile
Only in XML-Atom-0.27_01-smart_link: Makefile.old
Only in XML-Atom-0.27_01: blib
Only in XML-Atom-0.27_01-smart_link/lib/XML/Atom: Content.pm~
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Entry.pm XML-Atom-0.27_01-smart_link/lib/XML/Atom/Entry.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Entry.pm 2006-08-16 14:40:46.000000000 +0900
+++ XML-Atom-0.27_01-smart_link/lib/XML/Atom/Entry.pm 2007-10-14 12:18:20.000000000 +0900
@@ -115,6 +115,19 @@
$link->href('http://www.example.com/2003/12/post.html');
$entry->add_link($link);
+=head2 $entry->alternate_link([ $href ])
+=head2 $entry->related_link([ $href ])
+=head2 $entry->self_link([ $href ])
+=head2 $entry->enclosure_link([ $href ])
+=head2 $entry->via_link([ $href ])
+=head2 $entry->edit_link([ $href ])
+=head2 $entry->edit_media_link([ $href ])
+
+Returns a value of I<href> attribute in I<XML::Atom::Link> object
+with an according relation such as I<alternate>.
+
+If $href is given, an I<XML::Atom::Link> object with a link the relation is set.
+
=head2 $entry->get($ns, $element)
Given an I<XML::Atom::Namespace> element I<$ns> and an element name
Only in XML-Atom-0.27_01-smart_link/lib/XML/Atom: Entry.pm~
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Feed.pm XML-Atom-0.27_01-smart_link/lib/XML/Atom/Feed.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Feed.pm 2006-09-08 03:38:12.000000000 +0900
+++ XML-Atom-0.27_01-smart_link/lib/XML/Atom/Feed.pm 2007-10-14 12:19:51.000000000 +0900
@@ -256,6 +256,21 @@
$link->href('http://www.example.com/');
$feed->add_link($link);
+=head2 $feed->alternate_link([ $href ])
+=head2 $feed->related_link([ $href ])
+=head2 $feed->self_link([ $href ])
+=head2 $feed->enclosure_link([ $href ])
+=head2 $feed->via_link([ $href ])
+=head2 $feed->first_link([ $href ])
+=head2 $feed->previous_link([ $href ])
+=head2 $feed->next_link([ $href ])
+=head2 $feed->last_link([ $href ])
+
+Returns a value of I<href> attribute in I<XML::Atom::Link> object
+with an according relation such as I<alternate>.
+
+If $href is given, an I<XML::Atom::Link> object with a link the relation is set.
+
=head2 $feed->add_entry($entry)
Adds the entry I<$entry>, which must be an I<XML::Atom::Entry> object,
Only in XML-Atom-0.27_01-smart_link/lib/XML/Atom: Feed.pm~
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Thing.pm XML-Atom-0.27_01-smart_link/lib/XML/Atom/Thing.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Thing.pm 2007-10-04 22:06:28.000000000 +0900
+++ XML-Atom-0.27_01-smart_link/lib/XML/Atom/Thing.pm 2007-10-14 12:08:13.000000000 +0900
@@ -120,4 +120,47 @@
};
}
+sub alternate_link {
+ my $atom = shift;
+ my @hrefs;
+ if (@_) {
+ my @links1 = grep { $_->rel && $_->rel ne 'alternate'} $atom->links;
+ my @links2 = map { my $link = XML::Atom::Link->new;
+ $link->rel('alternate');
+ $link->href($_);
+ $link }
+ @_;
+ $atom->link( @links1, @links2 );
+ @hrefs = @_;
+ }
+ else {
+ @hrefs = map { $_->href } grep { ! $_->rel || $_->rel eq 'alternate' } $atom->links;
+ }
+ return wantarray ? @hrefs : $hrefs[0];
+}
+
+for my $rel qw( self edit edit-media related enclosure via first previous next last ) {
+ no strict 'refs'; ## no critic
+ my $meth = join '_', $rel, 'link';
+ $meth =~ s/-/_/g;
+ *{ $meth } = sub {
+ my $atom = shift;
+ my @hrefs;
+ if (@_) {
+ my @links1 = grep { ! $_->rel || $_->rel ne $rel } $atom->links;
+ my @links2 = map { my $link = XML::Atom::Link->new;
+ $link->rel( $rel );
+ $link->href($_);
+ $link }
+ @_;
+ $atom->link( @links1, @links2 );
+ @hrefs = @_;
+ }
+ else {
+ @hrefs = map { $_->href } grep { $_->rel && $_->rel eq $rel } $atom->links;
+ }
+ return wantarray ? @hrefs : $hrefs[0];
+ };
+}
+
1;
Only in XML-Atom-0.27_01-smart_link/lib/XML/Atom: Thing.pm~
Only in XML-Atom-0.27_01: pm_to_blib
Only in XML-Atom-0.27_01-smart_link/t: 02-content.t~
diff -bru XML-Atom-0.27_01/t/11-entry.t XML-Atom-0.27_01-smart_link/t/11-entry.t
--- XML-Atom-0.27_01/t/11-entry.t 2006-11-26 07:47:18.000000000 +0900
+++ XML-Atom-0.27_01-smart_link/t/11-entry.t 2007-10-14 11:57:40.000000000 +0900
@@ -12,7 +12,7 @@
plan skip_all => 'euc-jp is not supported on your XML library';
}
-plan tests => 71;
+plan tests => 79;
my $entry;
@@ -160,3 +160,20 @@
$entry = XML::Atom::Entry->new('t/samples/entry-euc.xml');
is $entry->title, 'ã²ã¹ããªã¼ãµã¼';
is $entry->content->body, '<p>æ¥æ¬èªã®ãã£ã¼ã</p>';
+
+# smart link accessors
+
+$entry = XML::Atom::Entry->new;
+$entry->alternate_link('http://www.example.com/blog/1.html');
+is $entry->alternate_link, 'http://www.example.com/blog/1.html';
+@link = $entry->link;
+is scalar(@link), 1;
+is $link[0]->rel, 'alternate';
+is $link[0]->href, 'http://www.example.com/blog/1.html';
+
+$entry->edit_link('http://www.example.com/atom/1.atom');
+is $entry->edit_link, 'http://www.example.com/atom/1.atom';
+@link = $entry->link;
+is scalar(@link), 2;
+is $link[1]->rel, 'edit';
+is $link[1]->href, 'http://www.example.com/atom/1.atom';
Only in XML-Atom-0.27_01-smart_link/t: 11-entry.t~
diff -bru XML-Atom-0.27_01/t/12-feed.t XML-Atom-0.27_01-smart_link/t/12-feed.t
--- XML-Atom-0.27_01/t/12-feed.t 2006-08-16 14:40:38.000000000 +0900
+++ XML-Atom-0.27_01-smart_link/t/12-feed.t 2007-10-13 23:54:12.000000000 +0900
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 32;
+use Test::More tests => 40;
use XML::Atom::Feed;
use URI;
@@ -70,3 +70,20 @@
is scalar @entries, 17;
is $entries[0]->title, 'Bar';
is $feed->title, 'dive into atom';
+
+# smart link accessors
+
+$feed = XML::Atom::Feed->new;
+$feed->self_link('http://www.example.com/blog');
+is $feed->self_link, 'http://www.example.com/blog';
+my @link = $feed->link;
+is scalar(@link), 1;
+is $link[0]->rel, 'self';
+is $link[0]->href, 'http://www.example.com/blog';
+
+$feed->next_link('http://www.example.com/blog?page=2');
+is $feed->next_link, 'http://www.example.com/blog?page=2';
+@link = $feed->link;
+is scalar(@link), 2;
+is $link[1]->rel, 'next';
+is $link[1]->href, 'http://www.example.com/blog?page=2';
Only in XML-Atom-0.27_01-smart_link/t: 12-feed.t~
Subject: | XML-Atom-0.27_01-atompub.patch |
Only in XML-Atom-0.27_01: Makefile
Only in XML-Atom-0.27_01-atompub: Makefile.old
Only in XML-Atom-0.27_01: blib
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Content.pm XML-Atom-0.27_01-atompub/lib/XML/Atom/Content.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Content.pm 2007-10-04 22:06:14.000000000 +0900
+++ XML-Atom-0.27_01-atompub/lib/XML/Atom/Content.pm 2007-10-14 12:08:41.000000000 +0900
@@ -4,7 +4,7 @@
use strict;
use base qw( XML::Atom::Base );
-__PACKAGE__->mk_attr_accessors(qw( type mode ));
+__PACKAGE__->mk_attr_accessors(qw( type mode src ));
__PACKAGE__->mk_xml_attr_accessors(qw( lang base ));
use Encode;
@@ -23,6 +23,9 @@
if ($param{Type}) {
$content->type($param{Type});
}
+ if ($param{Src}) {
+ $content->src($param{Src});
+ }
return $content;
}
Only in XML-Atom-0.27_01-atompub/lib/XML/Atom: Content.pm~
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Entry.pm XML-Atom-0.27_01-atompub/lib/XML/Atom/Entry.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Entry.pm 2006-08-16 14:40:46.000000000 +0900
+++ XML-Atom-0.27_01-atompub/lib/XML/Atom/Entry.pm 2007-10-14 12:08:32.000000000 +0900
@@ -32,6 +32,29 @@
# OMG 0.3 elements ... to be backward compatible
__PACKAGE__->mk_elem_accessors(qw( created ));
+sub edited {
+ my $entry = shift;
+ my $ns = XML::Atom::Namespace->new( app => 'http://www.w3.org/2007/app' );
+ if (@_) {
+ $entry->set( $ns, 'edited', $_[0] );
+ }
+ else {
+ $entry->get( $ns, 'edited' );
+ }
+}
+
+__PACKAGE__->mk_object_list_accessor( 'control' => 'XML::Atom::Control' );
+
+package XML::Atom::Control;
+
+use base qw( XML::Atom::Base );
+
+__PACKAGE__->mk_elem_accessors(qw( draft ));
+
+sub element_name { 'control' }
+
+sub element_ns { 'http://www.w3.org/2007/app' }
+
1;
__END__
@@ -115,6 +138,18 @@
$link->href('http://www.example.com/2003/12/post.html');
$entry->add_link($link);
+=head2 $entry->control([ $control ])
+
+Returns an L<XML::Atom::Control> object representing the control of the
+Entry, or C<undef> if there is no control.
+
+If $control is supplied, it should be an L<XML::Atom::Control> object
+representing the control. For example:
+
+ my $control = XML::Atom::Control->new;
+ $control->draft('yes');
+ $entry->control($control);
+
=head2 $entry->get($ns, $element)
Given an I<XML::Atom::Namespace> element I<$ns> and an element name
Only in XML-Atom-0.27_01-atompub/lib/XML/Atom: Entry.pm~
Only in XML-Atom-0.27_01-atompub/lib/XML/Atom: Thing.pm~
Only in XML-Atom-0.27_01: pm_to_blib
diff -bru XML-Atom-0.27_01/t/02-content.t XML-Atom-0.27_01-atompub/t/02-content.t
--- XML-Atom-0.27_01/t/02-content.t 2006-11-23 03:55:19.000000000 +0900
+++ XML-Atom-0.27_01-atompub/t/02-content.t 2007-10-13 23:50:50.000000000 +0900
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 32;
+use Test::More tests => 35;
use XML::Atom::Content;
my $content;
@@ -97,3 +97,13 @@
Encode::_utf8_off($foo);
$foo;
}
+
+# AtomPub
+
+$content = XML::Atom::Content->new;
+$content->src('http://www.example.com/media/foo.bar');
+is $content->src, 'http://www.example.com/media/foo.bar';
+
+$content = XML::Atom::Content->new(Type => 'foo/bar', Src => 'http://www.example.com/media/foo.bar');
+is $content->type, 'foo/bar';
+is $content->src, 'http://www.example.com/media/foo.bar';
Only in XML-Atom-0.27_01-atompub/t: 02-content.t~
diff -bru XML-Atom-0.27_01/t/11-entry.t XML-Atom-0.27_01-atompub/t/11-entry.t
--- XML-Atom-0.27_01/t/11-entry.t 2006-11-26 07:47:18.000000000 +0900
+++ XML-Atom-0.27_01-atompub/t/11-entry.t 2007-10-14 11:55:33.000000000 +0900
@@ -12,7 +12,7 @@
plan skip_all => 'euc-jp is not supported on your XML library';
}
-plan tests => 71;
+plan tests => 73;
my $entry;
@@ -86,6 +86,16 @@
is $link[2]->href, 'http://www.example.com/atom';
is $link[2]->title, 'Number Three';
+# AtomPub
+
+$entry->edited('2007-01-01T00:00:00Z');
+is $entry->edited, '2007-01-01T00:00:00Z';
+
+my $control = XML::Atom::Control->new;
+$control->draft('yes');
+$entry->control($control);
+is $entry->control->draft, 'yes';
+
## xxx test setting/getting different content encodings
## xxx encodings
## xxx Doc param
Only in XML-Atom-0.27_01-atompub/t: 11-entry.t~
Only in XML-Atom-0.27_01-atompub/t: 12-feed.t~
Subject: | XML-Atom-0.27_01-all_in_one.patch |
Only in XML-Atom-0.27_01: Makefile
Only in XML-Atom-0.27_01-all_in_one: Makefile.old
Only in XML-Atom-0.27_01: blib
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Base.pm XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Base.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Base.pm 2007-10-04 22:07:39.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Base.pm 2007-10-14 12:22:49.000000000 +0900
@@ -338,6 +338,59 @@
};
}
+# accessors to text elements, multiple which there can be
+sub mk_elem_list_accessor {
+ my $class = shift;
+ my($name, $moniker) = @_;
+
+ no strict 'refs'; ## no critic
+
+ *{"$class\::$name"} = sub {
+ my $obj = shift;
+
+ my $ns_uri = $class->element_ns || $obj->ns;
+ if (@_) {
+ # setter: clear existent elements first
+ my @elem = childlist($obj->elem, $ns_uri, $name);
+ for my $el (@elem) {
+ $obj->elem->removeChild($el);
+ }
+
+ # add the new elements for each
+ my $adder = "add_$name";
+ for my $add_elem (@_) {
+ $obj->$adder($add_elem);
+ }
+ } else {
+ # getter:
+ my @children = map { $_->textContent } childlist( $obj->elem, $ns_uri, $name );
+ wantarray ? @children : $children[0];
+ }
+ };
+
+ if ($moniker) {
+ *{"$class\::$moniker"} = sub {
+ my $obj = shift;
+ if (@_) {
+ return $obj->$name(@_);
+ } else {
+ my @obj = $obj->$name;
+ return wantarray ? @obj : \@obj;
+ }
+ };
+ }
+
+ *{"$class\::add_$name"} = sub {
+ my $obj = shift;
+ my($stuff) = @_;
+
+ my $ns_uri = $class->element_ns || $obj->ns;
+ my $elem = create_element( $ns_uri, 'accept' );
+ $elem->appendText($stuff);
+ $obj->elem->appendChild($elem);
+ };
+}
+
sub as_xml {
my $obj = shift;
if (LIBXML) {
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Content.pm XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Content.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Content.pm 2007-10-04 22:06:14.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Content.pm 2007-10-14 12:21:16.000000000 +0900
@@ -4,7 +4,7 @@
use strict;
use base qw( XML::Atom::Base );
-__PACKAGE__->mk_attr_accessors(qw( type mode ));
+__PACKAGE__->mk_attr_accessors(qw( type mode src ));
__PACKAGE__->mk_xml_attr_accessors(qw( lang base ));
use Encode;
@@ -23,6 +23,9 @@
if ($param{Type}) {
$content->type($param{Type});
}
+ if ($param{Src}) {
+ $content->src($param{Src});
+ }
return $content;
}
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Entry.pm XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Entry.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Entry.pm 2006-08-16 14:40:46.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Entry.pm 2007-10-14 12:21:37.000000000 +0900
@@ -32,6 +32,29 @@
# OMG 0.3 elements ... to be backward compatible
__PACKAGE__->mk_elem_accessors(qw( created ));
+sub edited {
+ my $entry = shift;
+ my $ns = XML::Atom::Namespace->new( app => 'http://www.w3.org/2007/app' );
+ if (@_) {
+ $entry->set( $ns, 'edited', $_[0] );
+ }
+ else {
+ $entry->get( $ns, 'edited' );
+ }
+}
+
+__PACKAGE__->mk_object_list_accessor( 'control' => 'XML::Atom::Control' );
+
+package XML::Atom::Control;
+
+use base qw( XML::Atom::Base );
+
+__PACKAGE__->mk_elem_accessors(qw( draft ));
+
+sub element_name { 'control' }
+
+sub element_ns { 'http://www.w3.org/2007/app' }
+
1;
__END__
@@ -115,6 +138,31 @@
$link->href('http://www.example.com/2003/12/post.html');
$entry->add_link($link);
+=head2 $entry->control([ $control ])
+
+Returns an L<XML::Atom::Control> object representing the control of the
+Entry, or C<undef> if there is no control.
+
+If $control is supplied, it should be an L<XML::Atom::Control> object
+representing the control. For example:
+
+ my $control = XML::Atom::Control->new;
+ $control->draft('yes');
+ $entry->control($control);
+
+=head2 $entry->alternate_link([ $href ])
+=head2 $entry->related_link([ $href ])
+=head2 $entry->self_link([ $href ])
+=head2 $entry->enclosure_link([ $href ])
+=head2 $entry->via_link([ $href ])
+=head2 $entry->edit_link([ $href ])
+=head2 $entry->edit_media_link([ $href ])
+
+Returns a value of I<href> attribute in I<XML::Atom::Link> object
+with an according relation such as I<alternate>.
+
+If $href is given, an I<XML::Atom::Link> object with a link the relation is set.
+
=head2 $entry->get($ns, $element)
Given an I<XML::Atom::Namespace> element I<$ns> and an element name
Only in XML-Atom-0.27_01-all_in_one/lib/XML/Atom: Entry.pm.orig
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Feed.pm XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Feed.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Feed.pm 2006-09-08 03:38:12.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Feed.pm 2007-10-14 12:21:37.000000000 +0900
@@ -256,6 +256,21 @@
$link->href('http://www.example.com/');
$feed->add_link($link);
+=head2 $feed->alternate_link([ $href ])
+=head2 $feed->related_link([ $href ])
+=head2 $feed->self_link([ $href ])
+=head2 $feed->enclosure_link([ $href ])
+=head2 $feed->via_link([ $href ])
+=head2 $feed->first_link([ $href ])
+=head2 $feed->previous_link([ $href ])
+=head2 $feed->next_link([ $href ])
+=head2 $feed->last_link([ $href ])
+
+Returns a value of I<href> attribute in I<XML::Atom::Link> object
+with an according relation such as I<alternate>.
+
+If $href is given, an I<XML::Atom::Link> object with a link the relation is set.
+
=head2 $feed->add_entry($entry)
Adds the entry I<$entry>, which must be an I<XML::Atom::Entry> object,
diff -bru XML-Atom-0.27_01/lib/XML/Atom/Thing.pm XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Thing.pm
--- XML-Atom-0.27_01/lib/XML/Atom/Thing.pm 2007-10-04 22:06:28.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/lib/XML/Atom/Thing.pm 2007-10-14 12:21:37.000000000 +0900
@@ -120,4 +120,47 @@
};
}
+sub alternate_link {
+ my $atom = shift;
+ my @hrefs;
+ if (@_) {
+ my @links1 = grep { $_->rel && $_->rel ne 'alternate'} $atom->links;
+ my @links2 = map { my $link = XML::Atom::Link->new;
+ $link->rel('alternate');
+ $link->href($_);
+ $link }
+ @_;
+ $atom->link( @links1, @links2 );
+ @hrefs = @_;
+ }
+ else {
+ @hrefs = map { $_->href } grep { ! $_->rel || $_->rel eq 'alternate' } $atom->links;
+ }
+ return wantarray ? @hrefs : $hrefs[0];
+}
+
+for my $rel qw( self edit edit-media related enclosure via first previous next last ) {
+ no strict 'refs'; ## no critic
+ my $meth = join '_', $rel, 'link';
+ $meth =~ s/-/_/g;
+ *{ $meth } = sub {
+ my $atom = shift;
+ my @hrefs;
+ if (@_) {
+ my @links1 = grep { ! $_->rel || $_->rel ne $rel } $atom->links;
+ my @links2 = map { my $link = XML::Atom::Link->new;
+ $link->rel( $rel );
+ $link->href($_);
+ $link }
+ @_;
+ $atom->link( @links1, @links2 );
+ @hrefs = @_;
+ }
+ else {
+ @hrefs = map { $_->href } grep { $_->rel && $_->rel eq $rel } $atom->links;
+ }
+ return wantarray ? @hrefs : $hrefs[0];
+ };
+}
+
1;
Only in XML-Atom-0.27_01: pm_to_blib
diff -bru XML-Atom-0.27_01/t/02-content.t XML-Atom-0.27_01-all_in_one/t/02-content.t
--- XML-Atom-0.27_01/t/02-content.t 2006-11-23 03:55:19.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/t/02-content.t 2007-10-14 12:21:16.000000000 +0900
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 32;
+use Test::More tests => 35;
use XML::Atom::Content;
my $content;
@@ -97,3 +97,13 @@
Encode::_utf8_off($foo);
$foo;
}
+
+# AtomPub
+
+$content = XML::Atom::Content->new;
+$content->src('http://www.example.com/media/foo.bar');
+is $content->src, 'http://www.example.com/media/foo.bar';
+
+$content = XML::Atom::Content->new(Type => 'foo/bar', Src => 'http://www.example.com/media/foo.bar');
+is $content->type, 'foo/bar';
+is $content->src, 'http://www.example.com/media/foo.bar';
diff -bru XML-Atom-0.27_01/t/11-entry.t XML-Atom-0.27_01-all_in_one/t/11-entry.t
--- XML-Atom-0.27_01/t/11-entry.t 2006-11-26 07:47:18.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/t/11-entry.t 2007-10-14 12:23:30.000000000 +0900
@@ -12,7 +12,7 @@
plan skip_all => 'euc-jp is not supported on your XML library';
}
-plan tests => 71;
+plan tests => 81;
my $entry;
@@ -86,6 +86,16 @@
is $link[2]->href, 'http://www.example.com/atom';
is $link[2]->title, 'Number Three';
+# AtomPub
+
+$entry->edited('2007-01-01T00:00:00Z');
+is $entry->edited, '2007-01-01T00:00:00Z';
+
+my $control = XML::Atom::Control->new;
+$control->draft('yes');
+$entry->control($control);
+is $entry->control->draft, 'yes';
+
## xxx test setting/getting different content encodings
## xxx encodings
## xxx Doc param
@@ -160,3 +170,20 @@
$entry = XML::Atom::Entry->new('t/samples/entry-euc.xml');
is $entry->title, 'ã²ã¹ããªã¼ãµã¼';
is $entry->content->body, '<p>æ¥æ¬èªã®ãã£ã¼ã</p>';
+
+# smart link accessors
+
+$entry = XML::Atom::Entry->new;
+$entry->alternate_link('http://www.example.com/blog/1.html');
+is $entry->alternate_link, 'http://www.example.com/blog/1.html';
+@link = $entry->link;
+is scalar(@link), 1;
+is $link[0]->rel, 'alternate';
+is $link[0]->href, 'http://www.example.com/blog/1.html';
+
+$entry->edit_link('http://www.example.com/atom/1.atom');
+is $entry->edit_link, 'http://www.example.com/atom/1.atom';
+@link = $entry->link;
+is scalar(@link), 2;
+is $link[1]->rel, 'edit';
+is $link[1]->href, 'http://www.example.com/atom/1.atom';
diff -bru XML-Atom-0.27_01/t/12-feed.t XML-Atom-0.27_01-all_in_one/t/12-feed.t
--- XML-Atom-0.27_01/t/12-feed.t 2006-08-16 14:40:38.000000000 +0900
+++ XML-Atom-0.27_01-all_in_one/t/12-feed.t 2007-10-14 12:21:37.000000000 +0900
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 32;
+use Test::More tests => 40;
use XML::Atom::Feed;
use URI;
@@ -70,3 +70,20 @@
is scalar @entries, 17;
is $entries[0]->title, 'Bar';
is $feed->title, 'dive into atom';
+
+# smart link accessors
+
+$feed = XML::Atom::Feed->new;
+$feed->self_link('http://www.example.com/blog');
+is $feed->self_link, 'http://www.example.com/blog';
+my @link = $feed->link;
+is scalar(@link), 1;
+is $link[0]->rel, 'self';
+is $link[0]->href, 'http://www.example.com/blog';
+
+$feed->next_link('http://www.example.com/blog?page=2');
+is $feed->next_link, 'http://www.example.com/blog?page=2';
+@link = $feed->link;
+is scalar(@link), 2;
+is $link[1]->rel, 'next';
+is $link[1]->href, 'http://www.example.com/blog?page=2';