XML::Loy::XRD - Extensible Resource Descriptor Extension
use XML::Loy::XRD; # Create new document my $xrd = XML::Loy::XRD->new; # Set subject and add alias $xrd->subject('http://sojolicio.us/'); $xrd->alias('https://sojolicio.us/'); # Add properties $xrd->property(describedBy => '/me.foaf' ); $xrd->property(private => undef); # Add links $xrd->link(lrdd => { template => '/.well-known/webfinger?resource={uri}' }); print $xrd->to_pretty_xml; # <?xml version="1.0" encoding="UTF-8" standalone="yes"?> # <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" # xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> # <Subject>http://sojolicio.us/</Subject> # <Alias>https://sojolicio.us/</Alias> # <Link rel="lrdd" # template="/.well-known/webfinger?resource={uri}" /> # <Property type="describedby">/me.foaf</Property> # <Property type="private" # xsi:nil="true" /> # </XRD> print $xrd->to_json; # {"subject":"http:\/\/sojolicio.us\/", # "aliases":["https:\/\/sojolicio.us\/"], # "links":[{"rel":"lrdd", # "template":"\/.well-known\/webfinger?resource={uri}"}], # "properties":{"private":null,"describedby":"\/me.foaf"}}
XML::Loy::XRD is a XML::Loy base class for handling Extensible Resource Descriptor documents with JRD support.
This code may help you to create your own XML::Loy extensions.
This module is an early release! There may be significant changes in the future.
XML::Loy::XRD inherits all methods from XML::Loy and implements the following new ones.
# Empty document my $xrd = XML::Loy::XRD->new; # New document by XRD $xrd = XML::Loy::XRD->new(<<'XRD'); <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Subject>http://sojolicio.us/</Subject> <Alias>https://sojolicio.us/</Alias> <Link rel="lrdd" template="/.well-known/webfinger?resource={uri}" /> <Property type="describedby">/me.foaf</Property> <Property type="private" xsi:nil="true" /> </XRD> XRD print $xrd->link('lrdd')->attr('template'); # New document by JRD my $jrd = XML::Loy::XRD->new(<<'JRD'); {"subject":"http:\/\/sojolicio.us\/", "aliases":["https:\/\/sojolicio.us\/"], "links":[{"rel":"lrdd", "template":"\/.well-known\/webfinger?resource={uri}"}], "properties":{"private":null,"describedby":"\/me.foaf"}} JRD print join ', ', $jrd->alias;
Create a new XRD document object. Beside the accepted input of XML::Loy::new, it can also parse JRD input.
$xrd->alias( 'https://sojolicio.us/', 'https://sojolicio.us' ); my @aliases = $xrd->alias;
Adds multiple aliases to the xrd document or returns an array of aliases.
Note: This is an experimental method and may be changed in further versions.
if ($xrd->expired) { print "Don't use this document anymore!" };
Returns a true value, if the document has expired based on the value of <Expires />, otherwise returns false.
true
<Expires />
false
$xrd->expires('1264843800'); # or $xrd->expires('2010-01-30T09:30:00Z'); print $xrd->expires->to_string;
Set an expiration date or get the expiration date as a XML::Loy::Date::RFC3339 object.
This method is experimental and may return another object with a different API!
my $new_xrd = $xrd->filter_rel(qw/lrdd author/); $new_xrd = $xrd->filter_rel('lrdd author'); $new_xrd = $xrd->filter_rel(['lrdd', 'author']); # New XRD without any link relations $new_xrd = $xrd->filter_rel;
Returns a cloned XRD document, with filtered links based on their relations. Accepts an array, an array reference, or a space separated string describing the relation types. See WebFinger for further information.
This method is experimental and may change without warnings!
# Add links my $link = $xrd->link(profile => '/me.html'); $xrd->link(hcard => { href => '/me.hcard' })->add(Title => 'My hcard'); # Get links print $xrd->link('lrdd')->attr('href'); # use Mojo::DOM remove method $xrd->link('hcard')->remove;
Adds links to the xrd document or retrieves them. Accepts the relation as a scalar and for adding either an additional hash reference containing the attributes, or a scalar value referring to the href attribute.
href
# Add properties $xrd->property(created => 'today'); my $prop = $xrd->property(private => undef); print prop->text; # Get properties my $prop = $xrd->property('created'); print prop->text; # use Mojo::DOM remove method $xrd->property('private')->remove;
Adds properties to the xrd document or retrieves them. To add empty properties, undef has to be passed as the property's value.
undef
$xrd->subject('http://sojolicio.us/'); my $subject = $xrd->subject;
Sets the subject of the xrd document or returns it.
print $xrd->to_json;
Returns a JSON string representing a JRD document.
When loaded as a base class, XML::Loy::XRD makes the mime-type application/xrd+xml available.
application/xrd+xml
Mojolicious.
https://github.com/Akron/XML-Loy
Copyright (C) 2011-2013, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the same terms as Perl.
To install XML::Loy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Loy
CPAN shell
perl -MCPAN -e shell install XML::Loy
For more information on module installation, please visit the detailed CPAN module installation guide.