Text-SimpleVcard

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;
use ExtUtils::MakeMaker;
use 5.6.1;

WriteMakefile(
    NAME                => 'Text::SimpleVcard',
    AUTHOR              => 'Michael Tomuschat <tomuschat@perl.org>',
    VERSION_FROM        => 'lib/Text/SimpleVcard.pm',
    ABSTRACT_FROM       => 'lib/Text/SimpleVcard.pm',
    PL_FILES            => {},
    PREREQ_PM => {
        'Test::More' => 0,
    },
    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean               => { FILES => 'Text-SimpleVcard-*' },
);

README  view on Meta::CPAN

	perl Makefile.PL
	make
	make test
	make install

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the
perldoc command.

    perldoc Text::SimpleVcard

You can also look for information at:

    RT, CPAN's request tracker
        http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-SimpleVcard

    AnnoCPAN, Annotated CPAN documentation
        http://annocpan.org/dist/Text-SimpleVcard

    CPAN Ratings

lib/Text/SimpleVcard.pm  view on Meta::CPAN

}

sub print {
   my( $class, $hdr) = @_;

   print $hdr if( $hdr);
   print $class->sprint() . "\n";
}

# ===========================================================================
# Text::SimpleVcard - a package to manage a single vCard
# ===========================================================================
package Text::SimpleVcard;

use warnings;
use strict;

=head1 NAME

Text::SimpleVcard - a package to manage a single vCard

=head1 VERSION

Version 0.05

=cut

our $VERSION = '0.05';

=head1 SYNOPSIS

lib/Text/SimpleVcard.pm  view on Meta::CPAN

simplevCard - This package provides an API to reading a single vCard. A vCard is an
electronic business card. You will find that many applications (KDE Address book,
Apple Address book, MS Outlook, Evolution, etc.) use and can export and import vCards.

This module offers only basic vcard features (folding, ...). Grouping, etc. is not yet
supported. Further enhancements are always welcome.

SimpleVcard has a minimum of dependencies (actually only 'MIME::QuotedPrint'), it
should work with every installation.

   use Text::SimpleVcard;

   open FH, "< std.vcf";        # 'std.vcf' contains a single vcard-entry
   my $vCard = Text::SimpleVcard->new( join( '', <FH>));
   $vCard->print();
   print "FN=" . $vCard->getSimpleValue( 'FN') . "\n";
   print "fullname=" . $vCard->getFullName() . "\n";
   my %h = $vCard->getValuesAsHash( 'TEL', [qw( WORK HOME)]);

   print "phone-numbers are:\n";
   foreach( keys %h) {
      print "Got number $_ ($h{$_})\n";
   }

lib/Text/SimpleVcard.pm  view on Meta::CPAN

=head1 BUGS

Please report any bugs or feature requests to C<bug-text-simplevcard at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Text-SimpleVcard>. I will 
be notified, and then you'll automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Text::SimpleVcard


You can also look for information at:

=over 4

=item * RT: CPAN's request tracker

L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-SimpleVcard>

lib/Text/SimpleVcard.pm  view on Meta::CPAN

=head1 COPYRIGHT & LICENSE

Copyright 2008-2009 Michael Tomuschat, all rights reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.


=cut

1; # End of Text::SimpleVcard

t/00-load.t  view on Meta::CPAN

#!perl -T

use Test::More tests => 1;

BEGIN {
	use_ok( 'Text::SimpleVcard' );
}

diag( "Testing Text::SimpleVcard $Text::SimpleVcard::VERSION, Perl $], $^X" );

t/vcard1.t  view on Meta::CPAN

use Test::More 'no_plan';
use Text::SimpleVcard;

my $dat = "BEGIN:VCARD\r\n" .
	  "ADR;TYPE=home:;;Musterstr. 23;Münster;;12345;\r\n" .
	  "BDAY:1968-05-19T00:00:00Z\r\n" .
	  "CLASS:PUBLIC\r\n" .
	  "EMAIL:a.bcd\@web.de\r\n" .
	  "FN:Tomuschat\\, Michael\r\n" .
	  "N:Tomuschat;Michael;;;\r\n" .
	  "ORG:Ing. Büro Tomuschat\r\n" .
	  "REV:2008-01-23T10:21:45Z\r\n" .
	  "TEL;TYPE=HOME:(04711) 12345\r\n" .
	  "TEL;TYPE=WORK:(04711) 123456\r\n" .
	  "TEL;TYPE=FAX;TYPE=WORK:(04711) 123457\r\n" .
	  "TEL;TYPE=CELL:(0815) 9876543\r\n" .
	  "UID:8\r\n" .
	  "VERSION:3.0\r\n" .
	  "END:VCARD\r\n";

my $vCard = Text::SimpleVcard->new( $dat);
my $fullname = $vCard->getFullName();
my $propFN = $vCard->getSimpleValue( 'FN');
my $propEmail = $vCard->getSimpleValue( 'EmaiL');
my $propTEL = $vCard->getSimpleValue( 'TEL', 2);
my $undef1 = $vCard->getSimpleValue( 'dummy');
my $undef2 = $vCard->getSimpleValue( 'FN', 27);
my %h1 = $vCard->getValuesAsHash( 'TEL', [qw( WORK HOME VOICE FAX)]);
my %h2 = $vCard->getValuesAsHash( 'TEL');
my @dat1 = split( /[\r\n]+/, $dat);
shift @dat1;
pop @dat1;
@dat1 = sort @dat1;
my @dat2 = sort split( /[\r\n]+/, $vCard->sprint());
my $dat1 = join( '\n', @dat1);
my $dat2 = join( '\n', @dat2);
ok( defined $vCard,                     'new() returning something');
ok( $vCard->isa( 'Text::SimpleVcard'),  'new() returning hash-reference of type SimpleVcard');
is( keys %$vCard, 11,                   'new() returning correct count of properties');
is( $fullname, 'Tomuschat, Michael',    'getFullName() returning correct fullname');
is( $propFN, 'Tomuschat\, Michael',     'getSimpleValue() returning correct FN-property');
is( $propEmail, 'a.bcd@web.de',         'getSimpleValue() with upper/lower spelling');
is( $propTEL, '(04711) 123457',         'getsimpleValue() with in-range-index');
is( $undef1, undef,                     'getSimpleValue() with unknown element');
is( $undef2, undef,                     'getSimpleValue() with index too big');
is( scalar( keys %h1), 3,               'getValuesAsHash() returning correct count of properties');
is( $h1{ '(04711) 123457'}, 'WORK,FAX', 'getValuesAsHash() returning correct types');
is( $h1{ '(04711) 123456'}, 'WORK',     'getValuesAsHash() returning correct types');

t/vcard2.t  view on Meta::CPAN

use Test::More 'no_plan';
use Text::SimpleVcard;

my $dat = "BEGIN:VCARD\r\n" .
	  "VERSION:2.1\r\n" .
	  "N:Gump;Forrest\r\n" .
	  "FN:Forrest Gump\r\n" .
	  "ORG:Bubba Gump Shrimp Co.\r\n" .
	  "TITLE:Shrimp Man\r\n" .
	  "TEL;WORK:(111) 555-1212\r\n" .
	  "TEL;HOME;VOICE:(404) 555-1212\r\n" .
	  "TEL;CELL:(404) 555-1212\r\n" .
	  "ADR;WORK:;;100 Waters Edge;Baytown;LA;30314;United States of America\r\n" .
	  "LABEL;WORK;ENCODING=QUOTED-PRINTABLE:100 Waters Edge=0D=0ABaytown, LA 30314=0D=0AUnited States of America\r\n" .
	  "ADR;HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America\r\n" .
	  "LABEL;HOME;ENCODING=QUOTED-PRINTABLE:42 Plantation St.=0D=0ABaytown, LA 30314=0D=0AUnited States of America\r\n" .
	  "EMAIL;PREF;INTERNET:forrestgump\@example.com\r\n" .
	  "REV:20080424T195243Z\r\n" .
	  "END:VCARD\r\n";

my $vCard = Text::SimpleVcard->new( $dat);
my $fullname = $vCard->getFullName();
my $propLBL1 = $vCard->getSimpleValueOfType( 'LABEL', [ 'WORK']); 
my $lbl1 = "100 Waters Edge\r\nBaytown, LA 30314\r\nUnited States of America";
my $propLBL2 = $vCard->getSimpleValue( 'LABEL', 1);
my $lbl2 = "42 Plantation St.\r\nBaytown, LA 30314\r\nUnited States of America";
my %h1 = $vCard->getValuesAsHash( 'TEL', [qw( WORK HOME)]);
my %h2 = $vCard->getValuesAsHash( 'TEL');

ok( defined $vCard,                     'new() returning something');
ok( $vCard->isa( 'Text::SimpleVcard'),  'new() returning hash-reference of type SimpleVcard');
is( keys %$vCard, 10,                   'new() returning correct count of properties');
is( $fullname, 'Forrest Gump',          'getFullName() returning correct fullname');
is( $propLBL1, $lbl1,                   'getsimpleValue() with in-range-index');
is( $propLBL2, $lbl2,                   'getsimpleValue() with in-range-index');
is( scalar( keys %h1), 2,               'getValuesAsHash() returning correct count of properties (1)');
is( scalar( keys %h2), 2,               'getValuesAsHash() returning correct count of properties (2)');
is( $h1{ '(404) 555-1212'}, 'HOME',     'getValuesAsHash() returning correct types');
is( $h1{ '(111) 555-1212'}, 'WORK',     'getValuesAsHash() returning correct types');
is( $h1{ '(0815) 9876543'}, undef,      'getValuesAsHash() returning correct types');
is( $h2{ '(404) 555-1212'}, 'HOME,VOICE,CELL', 'getValuesAsHash() returning correct types when no types provided');



( run in 0.782 second using v1.01-cache-2.11-cpan-5fbc6bb55f2 )