Permalink
Browse files

Merge pull request #2 from szabgab/master

please integrate and releases
  • Loading branch information...
2 parents 40cd1d2 + f93f830 commit 9735a1946f47df4ae3edc62e2b625d81e3783e89 @ranguard committed May 31, 2012
Showing with 67 additions and 16 deletions.
  1. +8 −0 .gitignore
  2. +5 −0 Makefile.PL
  3. +10 −8 lib/Text/vCard.pm
  4. +19 −3 lib/Text/vCard/Addressbook.pm
  5. +3 −2 lib/Text/vCard/Node.pm
  6. +22 −3 t/05-export.t
View
@@ -0,0 +1,8 @@
+MYMETA.json
+MYMETA.yml
+Makefile
+Text-vCard-*
+blib
+pm_to_blib
+*.swp
+
View
@@ -12,6 +12,11 @@ WriteMakefile(
'Test::More' => '0.1',
},
'VERSION_FROM' => 'lib/Text/vCard.pm',
+ 'META_MERGE' => {
+ resources => {
+ repository => 'http://github.com/ranguard/text-vcard',
+ },
+ },
'dist' => {'COMPRESS' => 'gzip -9f', 'SUFFIX' => 'gz'},
);
View
@@ -1,8 +1,9 @@
package Text::vCard;
-use 5.006; #warnings.pm
+use 5.006;
use Carp;
use strict;
+use warnings;
use File::Slurp;
use Text::vFile::asData;
use Text::vCard::Node;
@@ -46,7 +47,7 @@ map { push( @simple, lc($_) ) } @simple;
# Generate the methods
{
no strict 'refs';
- no warnings;
+ no warnings 'redefine';
# 'version' handled separately
# to prevent conflict with ExtUtils::MakeMaker
@@ -84,7 +85,8 @@ Text::vCard - a package to edit and create a single vCard (RFC 2426)
=head1 WARNING
-You probably want to start with Text::vCard::Addressbook, then this module.
+To handle a whole addressbook with several vCard entries in it, you probably
+want to start with L<Text::vCard::Addressbook>, then this module.
This is not backwards compatable with 1.0 or earlier versions!
@@ -105,7 +107,7 @@ This package is for a single vCard (person / record / set of address information
It provides an API to editing and creating vCards, or supplied a specific piece
of the Text::vFile::asData results it generates a vCard with that content.
-You should really use Text::vCard::Addressbook as this handles creating
+You should really use L<Text::vCard::Addressbook> as this handles creating
vCards from an existing file for you.
=head1 METHODS
@@ -164,8 +166,8 @@ my $address = $vcard->add_node({
'node_type' => 'ADR',
});
-This creates a new address in the vCard which you can then call the
-address methods on. See below for what options are available.
+This creates a new address (a L<Text::vCard::Node> object) in the vCard
+which you can then call the address methods on. See below for what options are available.
The node_type parameter must conform to the vCard spec format (e.g. ADR not address)
@@ -204,7 +206,7 @@ The following method allows you to extract the contents from the vCard.
'types' => \@types,
});
-Either an array or array ref is returned, containing Text::vCard::Node objects.
+Either an array or array ref is returned, containing L<Text::vCard::Node> objects.
If there are no results of 'node_type' undef is returned.
Supplied with a scalar or an array ref the methods
@@ -568,7 +570,7 @@ it and/or modify it under the same terms as Perl itself.
=head1 SEE ALSO
-Text::vCard::Addressbook, Text::vCard::Node
+L<Text::vCard::Addressbook>, L<Text::vCard::Node>
=cut
@@ -2,6 +2,7 @@ package Text::vCard::Addressbook;
use Carp;
use strict;
+use warnings;
use File::Slurp;
use Text::vFile::asData;
use Text::vCard;
@@ -15,6 +16,8 @@ Text::vCard::Addressbook - a package to parse, edit and create multiple vCards (
=head1 SYNOPSIS
+To read an existing file:
+
use Text::vCard::Addressbook;
my $address_book = Text::vCard::Addressbook->new({
@@ -25,6 +28,19 @@ Text::vCard::Addressbook - a package to parse, edit and create multiple vCards (
print "Got card for " . $vcard->fullname() . "\n";
}
+To create a new file:
+
+ use Text::vCard::Addressbook;
+
+ my $address_book = Text::vCard::Addressbook->new();
+ my $vcard = $ab->add_vcard;
+ $vcard->fullname('Foo Bar');
+ $vcard->EMAIL('foo@bar.com');
+
+ open my $out, '>', 'address.vcf' or die;
+ print $out $address_book->export;
+
+
=head1 DESCRIPTION
This package provides an API to reading / editing and creating
@@ -133,7 +149,7 @@ sub new {
my $vcard = $address_book->add_vcard();
-This method creates a new empty Text::vCard object, stores it in the
+This method creates a new empty L<Text::vCard> object, stores it in the
address book and return it so you can add data to it.
=cut
@@ -307,11 +323,11 @@ it and/or modify it under the same terms as Perl itself.
=head1 ACKNOWLEDGEMENTS
-The authors of Text::vFile::asData for making my life so much easier.
+The authors of L<Text::vFile::asData> for making my life so much easier.
=head1 SEE ALSO
-Text::vCard, Text::vCard::Node
+L<Text::vCard>, L<Text::vCard::Node>
=cut
@@ -1,6 +1,7 @@
package Text::vCard::Node;
use strict;
+use warnings;
use Carp;
use MIME::QuotedPrint;
use vars qw ( $AUTOLOAD );
@@ -30,7 +31,7 @@ Text::vCard::Node - Object for each node (line) of a vCard
Package used by Text::vCard so that each element: ADR, N, TEL etc are objects.
-You should not need to use this module directly, Text::vCard does it all for you.
+You should not need to use this module directly, L<Text::vCard> does it all for you.
=head1 METHODS
@@ -385,7 +386,7 @@ Leo Lapworth, LLAP@cuckoo.org
=head1 SEE ALSO
-Text::vCard Text::vCard::Addressbook
+L<Text::vCard> L<Text::vCard::Addressbook>
=cut
View
@@ -4,7 +4,7 @@ use strict;
use lib qw(./lib);
-use Test::More tests => 5;
+use Test::More tests => 10;
use Data::Dumper;
# Check we can load module
@@ -63,8 +63,27 @@ is_deeply(\@lines,\@data,'set_encoding() - returned data matched that expected')
#my $res = $notes->export();
#print Dumper($res);
-
-
+{
+ my $ab = Text::vCard::Addressbook->new();
+ is $ab->export, '', 'export empty addressbook';
+ my $vcard = $ab->add_vcard;
+ isa_ok $vcard, 'Text::vCard';
+ like $ab->export, qr{^BEGIN:VCARD\s+END:VCARD$}, 'single empty vcard';
+ $vcard->fullname('Foo Bar');
+ $vcard->EMAIL('foo@bar.com');
+ my $node = $vcard->add_node({
+ 'node_type' => 'TEL',
+# fields => ['TYPE'],
+# data => { TYPE => 'Work' },
+ });
+ isa_ok $node, 'Text::vCard::Node';
+ #$vcard->TEL('01-23456789');
+ eval {
+ $vcard->random_field('Something else');
+ };
+ like $@, qr{Can't locate object method "random_field" via package "Text::vCard"}, 'exception';
+ #diag $ab->export;
+}

0 comments on commit 9735a19

Please sign in to comment.