| 1 | package XML::Loy::OStatus; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use XML::Loy with => ( | ||
| 6 | prefix => 'ostatus', | ||
| 7 | namespace => 'http://ostatus.org/schema/1.0/' | ||
| 8 | ); | ||
| 9 | |||
| 10 | use Carp qw/carp/; | ||
| 11 | |||
| 12 | # No constructor | ||
| 13 | sub new { | ||
| 14 | carp 'Only use ' . __PACKAGE__ . ' as an extension to Atom'; | ||
| 15 | return; | ||
| 16 | }; | ||
| 17 | |||
| 18 | |||
| 19 | # Add 'attention' link | ||
| 20 | sub attention { | ||
| 21 | shift->_ostatus_link( attention => @_ ); | ||
| 22 | }; | ||
| 23 | |||
| 24 | |||
| 25 | # Add 'conversation' link | ||
| 26 | sub conversation { | ||
| 27 | shift->_ostatus_link( conversation => @_ ); | ||
| 28 | }; | ||
| 29 | |||
| 30 | |||
| 31 | # Link elements | ||
| 32 | sub _ostatus_link { | ||
| 33 | my $self = shift; | ||
| 34 | my $rel = 'ostatus:' . shift; | ||
| 35 | |||
| 36 | # Get href from link element | ||
| 37 | unless (@_) { | ||
| 38 | my $att = $self->link($rel) or return; | ||
| 39 | $att = $att->[0] or return; | ||
| 40 | return $att->attr('href'); | ||
| 41 | }; | ||
| 42 | |||
| 43 | # Create new link element | ||
| 44 | return $self->link( | ||
| 45 | rel => $rel, | ||
| 46 | href => shift, | ||
| 47 | @_ | ||
| 48 | ); | ||
| 49 | }; | ||
| 50 | |||
| 51 | |||
| 52 | # OStatus activity 'leave' | ||
| 53 | sub verb_leave { | ||
| 54 | shift->verb( __PACKAGE__->_namespace . 'leave'); | ||
| 55 | }; | ||
| 56 | |||
| 57 | |||
| 58 | # OStatus activity 'unfollow' | ||
| 59 | sub verb_unfollow { | ||
| 60 | shift->verb( __PACKAGE__->_namespace . 'unfollow'); | ||
| 61 | }; | ||
| 62 | |||
| 63 | |||
| 64 | # OStatus activity 'unfavorite' | ||
| 65 | sub verb_unfavorite { | ||
| 66 | shift->verb( __PACKAGE__->_namespace . 'unfavorite'); | ||
| 67 | }; | ||
| 68 | |||
| 69 | |||
| 70 | 1; | ||
| 71 | |||
| 72 | |||
| 73 | __END__ |