| 1 | package BBDB::Export::vCard; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.015'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our @ISA = qw(BBDB::Export); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Text::vFile::asData; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | #_* To Do | ||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||
| 16 | # BDAY birthday | ||||||||||||||||||||||||||||
| 17 | # MAILER | ||||||||||||||||||||||||||||
| 18 | # TZ timezone | ||||||||||||||||||||||||||||
| 19 | # TITLE | ||||||||||||||||||||||||||||
| 20 | # ROLE | ||||||||||||||||||||||||||||
| 21 | # PRODID | ||||||||||||||||||||||||||||
| 22 | # REV | ||||||||||||||||||||||||||||
| 23 | # SORT-STRING | ||||||||||||||||||||||||||||
| 24 | # UID | ||||||||||||||||||||||||||||
| 25 | # URL | ||||||||||||||||||||||||||||
| 26 | # CLASS | ||||||||||||||||||||||||||||
| 27 | # NICKNAME | ||||||||||||||||||||||||||||
| 28 | # PHOTO | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||
| 31 | #_* config | ||||||||||||||||||||||||||||
| 32 | # | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # supported keys, in preferred order | ||||||||||||||||||||||||||||
| 35 | # TODO: make this configurable | ||||||||||||||||||||||||||||
| 36 | 1 | my @keys = qw( begin version fn n org note tel email end); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # | ||||||||||||||||||||||||||||
| 39 | #_* process_record | ||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub process_record | ||||||||||||||||||||||||||||
| 43 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
process_record: called CC=7 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 7 | my ( $self, $record ) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 7 | my $vcard = Text::vFile::asData->new(); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 7 | my $data; | |||||||||||||||||||||||||||
| 50 | 7 | $data->{'properties'}->{'begin'} = [ { value => "vcard" } ]; | |||||||||||||||||||||||||||
| 51 | 7 | $data->{'properties'}->{'version'} = [ { value => "3.0" } ]; | |||||||||||||||||||||||||||
| 52 | 7 | $data->{'properties'}->{'fn'} = [ { value => $record->{'full'} } ]; | |||||||||||||||||||||||||||
| 53 | $data->{'properties'}->{'n'} = [ { value => join ";", ( | ||||||||||||||||||||||||||||
| 54 | $record->{'last'}, | ||||||||||||||||||||||||||||
| 55 | 7 | $record->{'first'}, | |||||||||||||||||||||||||||
| 56 | "", | ||||||||||||||||||||||||||||
| 57 | "", | ||||||||||||||||||||||||||||
| 58 | "" | ||||||||||||||||||||||||||||
| 59 | ) | ||||||||||||||||||||||||||||
| 60 | } ]; | ||||||||||||||||||||||||||||
| 61 | 7 | $data->{'properties'}->{'org'} = [ { value => $record->{'company'} } ]; | |||||||||||||||||||||||||||
| 62 | 7 | $data->{'properties'}->{'note'} = [ { value => $record->{'notes'} } ]; | |||||||||||||||||||||||||||
| 63 | $data->{'properties'}->{'tel'} = [ | ||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | value => $record->{'phone'}->{'home' }, | ||||||||||||||||||||||||||||
| 66 | param => { | ||||||||||||||||||||||||||||
| 67 | type => "home", | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | value => $record->{'phone'}->{'work' }, | ||||||||||||||||||||||||||||
| 73 | param => { | ||||||||||||||||||||||||||||
| 74 | type => "work", | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||||||||
| 79 | value => $record->{'phone'}->{'mobile' }, | ||||||||||||||||||||||||||||
| 80 | param => { | ||||||||||||||||||||||||||||
| 81 | type => "mobile", | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | 7 | value => $record->{'phone'}->{'fax' }, | |||||||||||||||||||||||||||
| 87 | param => { | ||||||||||||||||||||||||||||
| 88 | type => "fax", | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | ]; | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 7 | ▶ | if ( $record->{ 'net' } && ref $record->{ 'net' } eq "ARRAY" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$record->{"net"} and ref $record->{"net"} eq "ARRAY"
MC/DC50%1/2
$record->{"net"} and ref $record->{"net"} eq "ARRAY"
$record->{"net"}
ref $record->{"net"} eq "ARRAY"
Truth table66%2/3
A and B
A= $record->{"net"}B= ref $record->{"net"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 2 | for my $index ( 0 .. $#{ $record->{ 'net' } } ) | |||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 4 | push @{ $data->{'properties'}->{'email'} }, { | |||||||||||||||||||||||||||
| 100 | 4 | value => $record->{'net'}->[$index], | |||||||||||||||||||||||||||
| 101 | param => { | ||||||||||||||||||||||||||||
| 102 | type => "internet", | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 7 | $data->{'properties'}->{'end'} = [ { value => "vcard" } ]; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 7 | my @lines = $self->_generate_lines( $data ); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 7 | my $return = join( "\n", @lines ); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 7 | ▶ | if ( my $dir = $self->{'data'}->{'output_dir'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 0 | my $file = join ( "_", ( $record->{'first'}, $record->{'last'} ) ); | |||||||||||||||||||||||||||
| 118 | 0 | $file =~ tr,A-Za-z\-_,,cd; | |||||||||||||||||||||||||||
| 119 | 0 | $file = $dir . "/" . $file; | |||||||||||||||||||||||||||
| 120 | 0 | $file .= ".vcf"; | |||||||||||||||||||||||||||
| 121 | 0 | print "Writing file: $file\n"; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | open ( my $vcard_fh, ">", $file ) or die "Unable to write vcard: $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | print $vcard_fh $return, "\n"; | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | close ( $vcard_fh ) or die "Error writing vcard: $file: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 7 | return $return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||
| 131 | #_* Text::vFile::asData::generate_lines needs a little work | ||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||
| 133 | sub _generate_lines | ||||||||||||||||||||||||||||
| 134 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_generate_lines: called CC=12 SCAR=26.1
| |||||||||||||||||||||||||||||
| 135 | 7 | my ( $self, $data ) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 7 | my @lines; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 7 | ▶ | push @lines, "BEGIN:$data->{type}" if exists $data->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 7 | ▶ | if (exists $data->{properties}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||
| 142 | # TODO: handle properties that are not listed in global @keys | ||||||||||||||||||||||||||||
| 143 | 7 | for my $name ( @keys ) | |||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 63 | ▶ | next unless $data->{properties}->{ $name }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 58 | my $v = $data->{properties}->{ $name }; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 58 | for my $value (@$v) { | |||||||||||||||||||||||||||
| 149 | 81 | ▶ | next unless $value->{'value'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | # XXX so we're taking params in preference to param, | ||||||||||||||||||||||||||||
| 151 | # let's be sure to document that when we document this | ||||||||||||||||||||||||||||
| 152 | # method | ||||||||||||||||||||||||||||
| 153 | my $param = join ';', '', map { | ||||||||||||||||||||||||||||
| 154 | 49 | my $hash = $_; | |||||||||||||||||||||||||||
| 155 | map { | ||||||||||||||||||||||||||||
| 156 | 49 | ▶ | "$_" . (defined $hash->{$_} ? "=" . $hash->{$_} : "") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | } keys %$hash | ||||||||||||||||||||||||||||
| 158 | 49 | ▶ | } @{ $value->{params} || [ $value->{param} ] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$value->{'params'} || [$value->{'param'}]
MC/DC0%0/1
$value->{'params'} || [$value->{'param'}]
$value->{'params'}
Truth table50%1/2
A
A= $value->{'params'}
| |||||||||||||||||||||||||||||
| 159 | 49 | push @lines, "$name$param:$value->{value}"; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 7 | ▶ | if (exists $data->{objects}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | push @lines, $self->generate_lines( $_ ) for @{ $data->{objects} } | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | 7 | ▶ | push @lines, "END:$data->{type}" if exists $data->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 7 | return @lines; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # | ||||||||||||||||||||||||||||
| 172 | #_* post_processing | ||||||||||||||||||||||||||||
| 173 | # | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # no post processing necessary for vcard since there is one entry per | ||||||||||||||||||||||||||||
| 176 | # file. | ||||||||||||||||||||||||||||
| 177 | sub post_processing | ||||||||||||||||||||||||||||
| 178 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
post_processing: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 7 | my ( $self, $output ) = @_; | |||||||||||||||||||||||||||
| 180 | 7 | return $output; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 1 | 1; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||