20 Nov 2008 07:56:19 UTC
- Distribution: Data-Microformat
- Module version: 0.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Issues (1)
- Testers (192 / 501 / 0)
- KwaliteeBus factor: 0
- 79.30% Coverage
- License: perl_5
- Activity24 month
- Download (22.25KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionUSSJOIN Brendan Francis O'Connorand 1 contributors
- Brendan O'Connor
Data::Microformat::hCard - A module to parse and create hCards
This documentation refers to Data::Microformat::hCard version 0.03.
use Data::Microformat::hCard; my $card = Data::Microformat::hCard->parse($a_web_page); print "The nickname we found in this hCard was:\n"; print $card->nickname."\n"; # To create a new hCard: my $new_card = Data::Microformat::hCard->new; $new_card->fn("Brendan O'Connor"); $new_card->nickname("USSJoin"); my $new_email = Data::Microformat::hCard::type->new; $new_email->kind("email"); $new_email->type("Perl"); $new_email->value("email@example.com"); $new_card->email($new_email); print "Here's the new hCard I've just made:\n"; print $new_card->to_hcard."\n";
This module exists both to parse existing hCards from web pages, and to create new hCards so that they can be put onto the Internet.
To use it to parse an existing hCard (or hCards), simply give it the content of the page containing them (there is no need to first eliminate extraneous content, as the module will handle that itself):
my $card = Data::Microformat::hCard->parse($content);
If you would like to get all the hCards on the webpage, simply ask using an array:
my @cards = Data::Microformat::hCard->parse($content);
The module respects nested hCards using the parsing rules defined in the spec, so if one hCard contains another, it will return one hCard with the other held in the relevant subpart, rather than two top-level hCards.
To create a new hCard, first create the new object:
my $card = Data::Microformat::hCard->new;
Then use the helper methods to add any data you would like. When you're ready to output the hCard, simply write
my $output = $card->to_hcard;
And $output will be filled with an hCard representation, using <div> tags exclusively with the relevant class names.
If you would like to have the parser determine the representative hCard for a page, simply pass the page's URL as an additional parameter to the
from_treemethods, and the appropriate property will be found if it can be determined.
For information on precisely what types of strings are intended for each hCard property, it is recommended to consult the vCARD specification, RFC 2426.
Each module in Data::Microformat provides two methods, singular_fields and plural_fields. These methods list the fields on that object that can have exactly one value, or multiple values, respectively. Their documentation also tries to provide some hint as to what the field might be used for.
To set a value in a field, simply write
To get a value, for either singular or plural fields, you may write
my $value = $object->field_name;
For plural fields, to get all the values, just make the call in array context; for instance,
my @values = $my_hcard->nickname;
A plural value with multiple values set will return just the first one when called in scalar context.
This method overrides but provides the same functionality as the method of the same name in Data::Microformat, with the optional addition of $source_url. If present, this latter term will trigger a search to find the "representative hCard" for the given page, using the specifications for representative hCard parsing; a card's status of representative or not can be found by calling the
is_representativemethod on it.
This method returns 1 if the card is known to be a "representative hCard," and 0 otherwise. Note that for the representative hCard to have been determined, the URL for the source webpage must have been passed to the
from_treemethod that created the hCard.
The hCard class name for an hCard; to wit, "vcard."
This is a method to list all the fields on an hCard that can hold exactly one value.
They are as follows:
The birthday of the hCard.
The class of the hCard, such as "public" or "private."
The familiar name of the hCard.
The geolocation of the hCard, which should be a Data::Microformat::geo object.
The name of the hCard, which should be a Data::Microformat::hCard::name object.
The sorting string of the hCard.
The globally unique identifier for the hCard.
The time zone for the hCard.
This is a method to list all the fields on an hCard that can hold multiple values.
They are as follows:
The address of the hCard.
The agent, which can be either a string or an hCard itself.
The category of the hCard.
The cemail attached to the hCard, which should be a Data::Microformat::hCard::type object.
The key (especially, the encryption key) of the hCard.
The label of the hCard.
The logo of the hCard; usually a URI for the logo.
The mailer for the hCard.
The nickname for the hCard.
The note for the hCard.
The organization for the hCard, which should be a Data::Microformat::hCard::organization object.
The photo of the hCard; usually a URI for the photo.
The revision of the hCard.
The role of the hCard.
The sound of the hCard; usually a URI for the sound.
The telephone number of the hCard, which should be a Data::Microformat::hCard::type object.
The title of the hCard.
The URL for the hCard.
This module relies upon the following other modules:
They are distributed in the same distribution as this module.
Please report any bugs or feature requests to
bug-data-microformat at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Data-Microformat. I will be notified,and then you'll automatically be notified of progress on your bug as I make changes.
<perl at ussjoin.com>
Copyright 2008, Six Apart Ltd. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
Module Install Instructions
To install Data::Microformat, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Data::Microformat
For more information on module installation, please visit the detailed CPAN module installation guide.