| 1 | package Net::vFile; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Encode qw(decode is_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This stuff will be in Net::vCalendar | ||||||||||||||||||||||||||||
| 8 | # use DateTime::Format::ICal; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Net::vFile - Generic module which can read and write "vFile" files such as vCard (RFC 2426) and vCalendar (RFC 2445). | ||||||||||||||||||||||||||||
| 13 | The result of loading this data is a collection of objects which will grant you easy access to the properties. Then | ||||||||||||||||||||||||||||
| 14 | the module can write your objects back to a data file. | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | use Net::vCard; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | my $cards = Net::vCard->loadFile( "foo.vCard", "blort.vCard", "whee.vCard" ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | foreach my $card (@$cards) { | ||||||||||||||||||||||||||||
| 23 | spam ( $card->EMAIL('default') ); | ||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DETAILS | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | The way this processor works is that it reads the vFile line by line. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 - BEGIN:(.*) tag | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | $1 is looked up in classMap; class is loaded; new object of this class is created | ||||||||||||||||||||||||||||
| 33 | ie/ $Net::vFile::classMap{'VCARD'}="Net::vCard"; | ||||||||||||||||||||||||||||
| 34 | $object=$classMap{'VCARD'}->new; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | n.b. classMap is a package variable for Net::vFile | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 - All lines are read and stored until a BEGIN tag (goto 1) or END tag (goto 3) is reached | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 - END:(.*) tag | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Signals that all entry data has been obtained and now the rows of data are processed | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 - Data is concatenated - thanks to Net::iCal for the strategy; the tag label and data are obtained | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 5 - The data handler is identified via $object->varHandler->{$label} | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | There are some generic handlers for common data types such as simple strings, dates, etc. More | ||||||||||||||||||||||||||||
| 49 | elaborate data types such as N, ADR, etc. need special treatment and are declared explititly | ||||||||||||||||||||||||||||
| 50 | in classes as "load_XXX" such as "load_N" | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | You should be able to override and extend the processing by taking Net::vCard.pm as your example | ||||||||||||||||||||||||||||
| 53 | and adjusting as necessary. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | The resulting data structure is a bit bulky - but is such that it can express vCard data completely and | ||||||||||||||||||||||||||||
| 56 | reliably | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Put in a dump of a vCard here | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 DEPENDENCIES | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | DateTime::Format::ICal | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =over 4 | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =item \@objects = loadFile( filename [, filename ... ] ) | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Loads the vFiles and returns an array of objects | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 4 | ▶ | sub loadFile { | ||||||||||||||||||||||||||
|
Subroutine
loadFile: called CC=7 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 4 | my $self=shift; | |||||||||||||||||||||||||||
| 75 | 4 | ▶ | $self=$self->new unless ref($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 4 | foreach my $fn (@_) { | |||||||||||||||||||||||||||
| 78 | 5 | my $fh; | |||||||||||||||||||||||||||
| 79 | 5 | ▶ | if (open $fh, $fn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 5 | ▶ | until (eof $fh) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 5 | $self->load($fh, $fn); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | } else { | ||||||||||||||||||||||||||||
| 84 | 0 | warn "Cannot open $fn\n"; | |||||||||||||||||||||||||||
| 85 | 0 | next; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 5 | close $fh; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Usually people only load one type - VCARD | ||||||||||||||||||||||||||||
| 91 | # - which will be represented by a single top level | ||||||||||||||||||||||||||||
| 92 | # hash entry | ||||||||||||||||||||||||||||
| 93 | # However it is not impossible to load VCARD, VCALENDAR and more all at once | ||||||||||||||||||||||||||||
| 94 | # - in which case they get a scalar hashref | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 4 | ▶ | if ( scalar values %$self == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 4 | ▶ | if ( scalar values %$self == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 4 | return (values %$self)[0]; | |||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | return $self; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Classes inject their desired mappings | ||||||||||||||||||||||||||||
| 109 | 5 | our %classMap=( | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # VCARD => "Net::vCard", | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # VCALENDAR => "Net::vCalendar", | ||||||||||||||||||||||||||||
| 114 | # VALARM => "Net::vCalendar::vAlarm", | ||||||||||||||||||||||||||||
| 115 | # VEVENT => "Net::vCalendar::vEvent", | ||||||||||||||||||||||||||||
| 116 | # VTODO => "Net::vCalendar::vTodo", | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | ); | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item $object = class->new | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | Make a new object | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 9 | ▶ | my $class = ref($_[0]) ? ref(shift) : shift; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 9 | my $self=bless {}, $class; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 9 | return $self; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item \@objects = Class->load( filehandle ) | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Loads data from file handle and creates objects as necessary | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 10 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: called CC=18 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 10 | my ($class, $self); | |||||||||||||||||||||||||||
| 146 | 10 | ▶ | if (ref ($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 10 | $self=shift; | |||||||||||||||||||||||||||
| 148 | 10 | $class=ref($self); | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||
| 151 | 0 | $class=shift; | |||||||||||||||||||||||||||
| 152 | 0 | $self=$class->new; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | 10 | my $fh =shift; | |||||||||||||||||||||||||||
| 155 | 10 | my $parent=shift; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 10 | ▶ | $self->{'_parent'}=$parent if ref $parent; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 10 | my @lines=(); | |||||||||||||||||||||||||||
| 160 | 10 | my $varHandler=$class->varHandler; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 10 | my $decoder; | |||||||||||||||||||||||||||
| 163 | 10 | $_ = <$fh>; | |||||||||||||||||||||||||||
| 164 | 10 | $decoder=Encode::find_encoding("UTF-8"); | |||||||||||||||||||||||||||
| 165 | 10 | ▶ | if ( /^\000/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 4 | $decoder=Encode::find_encoding("UTF-16BE"); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 10 | ▶ | if ( /^[^\000]\000/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | $decoder=Encode::find_encoding("UTF-16LE"); | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 10 | my $thing=""; | |||||||||||||||||||||||||||
| 173 | 10 | ▶ | while ( $_ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 81 | my $line = $decoder->decode($_); | |||||||||||||||||||||||||||
| 176 | 81 | $line =~ s/[\r\n]+$//; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 81 | ▶ | if ($line =~ /^BEGIN:(.+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 5 | $thing=$1; | |||||||||||||||||||||||||||
| 180 | 5 | ▶ | my $subclass= $classMap{uc $thing} || die "Don't know how to load ${thing}s\n"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$Net::vFile::classMap{uc $thing} || die("Don't know how to load ${thing}s\n")
MC/DC0%0/1
$Net::vFile::classMap{uc $thing} || die("Don't know how to load ${thing}s\n")
$Net::vFile::classMap{uc $thing}
Truth table50%1/2
A
A= $Net::vFile::classMap{uc $thing}
| |||||||||||||||||||||||||||||
| 181 | 5 | ▶ | eval "use $subclass"; die $@ if $@; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | 5 | push @{$self->{$thing}}, $subclass->new->load($fh, $self); | |||||||||||||||||||||||||||
| 183 | 5 | next; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 76 | ▶ | last if $line =~ /^END:${thing}/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 66 | push @lines, $line; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 66 | $_ = <$fh>; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 10 | ▶ | while ( @lines ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 66 | my $line = shift @lines; | |||||||||||||||||||||||||||
| 196 | 66 | ▶ | while ( @lines && $lines[0] =~ /^\s(.*)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@lines and $lines[0] =~ /^\s(.*)/
MC/DC0%0/2
@lines and $lines[0] =~ /^\s(.*)/
@lines
$lines[0] =~ /^\s(.*)/
Truth table66%2/3
A and B
A= @linesB= $lines[0] =~ /^\s(.*)/
| |||||||||||||||||||||||||||||
| 197 | 0 | $line .= $1; | |||||||||||||||||||||||||||
| 198 | 0 | shift @lines; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # Non-typed line data | ||||||||||||||||||||||||||||
| 202 | 66 | ▶ | if ( $line =~ /^([\w\-]+):(.*)/ && exists $varHandler->{$1} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ /^([\w\-]+):(.*)/ and exists $varHandler->{$1}
MC/DC50%1/2
$line =~ /^([\w\-]+):(.*)/ and exists $varHandler->{$1}
$line =~ /^([\w\-]+):(.*)/
exists $varHandler->{$1}
Truth table66%2/3
A and B
A= $line =~ /^([\w\-]+):(.*)/B= exists $varHandler->{$1}
| |||||||||||||||||||||||||||||
| 203 | 27 | my $h="load_$varHandler->{$1}"; | |||||||||||||||||||||||||||
| 204 | 27 | $self->$h($1, undef, $2); | |||||||||||||||||||||||||||
| 205 | 27 | next; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # Typed line data | ||||||||||||||||||||||||||||
| 209 | 39 | ▶ | if ( $line =~ /^([\w\-]+);([^:]*):(.*)/ && exists $varHandler->{$1} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$line =~ /^([\w\-]+);([^:]*):(.*)/ and exists $varHandler->{$1}
MC/DC50%1/2
$line =~ /^([\w\-]+);([^:]*):(.*)/ and exists $varHandler->{$1}
$line =~ /^([\w\-]+);([^:]*):(.*)/
exists $varHandler->{$1}
Truth table66%2/3
A and B
A= $line =~ /^([\w\-]+);([^:]*):(.*)/B= exists $varHandler->{$1}
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 24 | my $h="load_$varHandler->{$1}"; | |||||||||||||||||||||||||||
| 212 | 24 | my ($var, $data)=($1, $3); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 24 | my %attr=(); | |||||||||||||||||||||||||||
| 215 | 24 | map { /([^=]+)=(.*)/; push @{$attr{uc $1}}, $2 } split (/(?<!\\);/, $2); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # XXX I want to split up the attributes here | ||||||||||||||||||||||||||||
| 218 | 24 | $self->$h($var, \%attr, $data); | |||||||||||||||||||||||||||
| 219 | 24 | next; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | # X-values | ||||||||||||||||||||||||||||
| 223 | 15 | ▶ | if ( $line =~ /^(X-[\w\-]+);?([^:]*):(.*)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 15 | my ($var, $data)=($1, $3); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 15 | my %attr=(); | |||||||||||||||||||||||||||
| 228 | 15 | map { /([^=]+)=(.*)/; push @{$attr{uc $1}}, $2 } split (/(?<!\\);/, $2); | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 15 | $self->load_singleTextTyped($var, \%attr, $data); | |||||||||||||||||||||||||||
| 231 | 15 | next; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | $self->error( $line ); | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 10 | return $self; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =item $object->error | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | Called when a line cannot be successfully decoded | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =back | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub error { warn ref($_[0]) . " ERRORLINE: $_[1]\n"; } | ||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =head1 DATA HANDLERS | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =over 4 | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =item varHandler | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Returns a hash ref mapping the item label to a handler name. Ie: | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||
| 261 | 'FN' => 'singleText', | ||||||||||||||||||||||||||||
| 262 | 'N' => 'N', | ||||||||||||||||||||||||||||
| 263 | 'NICKNAME' => 'multipleText', | ||||||||||||||||||||||||||||
| 264 | 'PHOTO' => 'singleBinary', | ||||||||||||||||||||||||||||
| 265 | 'BDAY' => 'singleText', | ||||||||||||||||||||||||||||
| 266 | 'ADR' => 'ADR', | ||||||||||||||||||||||||||||
| 267 | }; | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | =cut | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub varHandler { | ||||||||||||||||||||||||||
|
Subroutine
varHandler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 272 | 0 | return {}; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | =item typeDefault | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | Additional information where handlers require type info. Such as ADR - is this | ||||||||||||||||||||||||||||
| 278 | a home, postal, or whatever? If not supplied the RFC specifies what types they should | ||||||||||||||||||||||||||||
| 279 | default to. | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | from vCard: | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||
| 284 | 'ADR' => [ qw(intl postal parcel work) ], | ||||||||||||||||||||||||||||
| 285 | 'LABEL' => [ qw(intl postal parcel work) ], | ||||||||||||||||||||||||||||
| 286 | 'TEL' => [ qw(voice) ], | ||||||||||||||||||||||||||||
| 287 | 'EMAIL' => [ qw(internet) ], | ||||||||||||||||||||||||||||
| 288 | }; | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | sub typeDefault { | ||||||||||||||||||||||||||
|
Subroutine
typeDefault: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 293 | 0 | return {}; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | =item load_singleText | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | Loads a single text item with no processing other than unescape text | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | =cut | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 22 | ▶ | sub load_singleText { | ||||||||||||||||||||||||||
|
Subroutine
load_singleText: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 22 | my $val=$_[3]; | |||||||||||||||||||||||||||
| 305 | 22 | $val=~s/\\([\n,])/$1/gs; | |||||||||||||||||||||||||||
| 306 | # $val=~s/\\n/\n/gs; | ||||||||||||||||||||||||||||
| 307 | 22 | $_[0]->{$_[1]}{'val'}=$val; | |||||||||||||||||||||||||||
| 308 | 22 | ▶ | $_[0]->{$_[1]}{'_attr'}=$_[2] if $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =item _singleText | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | Accessor for single text items | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | =cut | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 1 | ▶ | sub _singleText { | ||||||||||||||||||||||||||
|
Subroutine
_singleText: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 1 | ▶ | if ($_[2]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | $_[0]->{$_[1]}{'val'}=$_[0]; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | 1 | return $_[0]->{$_[1]}{'val'}; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | =item load_singleDate | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | Loads a date creating a DateTime::Format::ICal object. Thanks Dave! | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =cut | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub load_singleDate { | ||||||||||||||||||||||||||
|
Subroutine
load_singleDate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | my $val=$_[3]; | |||||||||||||||||||||||||||
| 336 | 0 | eval { | |||||||||||||||||||||||||||
| 337 | 0 | $_[0]->{$_[1]}{'val'}=DateTime::Format::ICal->parse_datetime( iso8601 => $val ); | |||||||||||||||||||||||||||
| 338 | 0 | ▶ | }; if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | warn "$val; $@\n"; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $_[0]->{$_[1]}{'_attr'}=$_[2] if $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | =item load_singleDuration | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | Loads a data duration using DateTime::Format::ICal. | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | =cut | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | sub load_singleDuration { | ||||||||||||||||||||||||||
|
Subroutine
load_singleDuration: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | my $val=$_[3]; | |||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | eval { | |||||||||||||||||||||||||||
| 356 | 0 | $_[0]->{$_[1]}{'val'}=DateTime::Format::ICal->parse_duration( $val ); | |||||||||||||||||||||||||||
| 357 | 0 | ▶ | }; if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 0 | warn "$val; $@\n"; | |||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||
| 361 | 0 | ▶ | $_[0]->{$_[1]}{'_attr'}=$_[2] if $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =item load_multipleText | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | This is text that is separated by commas. The text is then unescaped. An array | ||||||||||||||||||||||||||||
| 368 | of items is created. | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | =cut | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 3 | ▶ | sub load_multipleText { | ||||||||||||||||||||||||||
|
Subroutine
load_multipleText: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 3 | my @vals=split /(?<!\\),/, $_[3]; | |||||||||||||||||||||||||||
| 375 | 3 | map { s/\\,/,/ } @vals; | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 3 | $_[0]->{$_[1]}{'val'}=\@vals; | |||||||||||||||||||||||||||
| 378 | 3 | ▶ | $_[0]->{$_[1]}{'_attr'}=$_[2] if $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =item load_singleTextType | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | Load text that has a type attribute. Each text of different type attributes | ||||||||||||||||||||||||||||
| 385 | will be handled independantly in as a hash entry. If no type attribute is supplied | ||||||||||||||||||||||||||||
| 386 | then the typeDefaults types will be used. A line can have multiple types. In the | ||||||||||||||||||||||||||||
| 387 | case where multiple types have the same value "_alias" indicators are created. | ||||||||||||||||||||||||||||
| 388 | The preferred type is stored in "_pref" | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =cut | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 28 | ▶ | sub load_singleTextTyped { | ||||||||||||||||||||||||||
|
Subroutine
load_singleTextTyped: called CC=9 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | 28 | my $typeDefault=$_[0]->typeDefault; | |||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | 28 | my $attr=$_[2]; | |||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 28 | my %type=(); | |||||||||||||||||||||||||||
| 399 | 28 | map { map { $type{lc $_}=1 } split /,/, $_ } @{$attr->{TYPE}}; | |||||||||||||||||||||||||||
| 400 | 0 | ▶ | map { $type{ lc $_ }=1 } @{$typeDefault->{$_[1]}} unless scalar(keys %type); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 28 | my $pref=0; | |||||||||||||||||||||||||||
| 403 | 28 | ▶ | if ($type{pref}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 25 | delete $type{pref}; | |||||||||||||||||||||||||||
| 405 | 25 | $pref=1; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | 28 | my @types=sort keys %type; | |||||||||||||||||||||||||||
| 409 | 28 | ▶ | my $actual=@types ? shift @types : "default"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 28 | $_[0]->{$_[1]}{$actual}=$_[3]; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 28 | ▶ | $_[0]->{$_[1]}{_pref}=$actual if $pref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 28 | ▶ | delete $_[0]->{$_[1]}{_alias}{$actual} if exists $_[0]->{$_[1]}{_alias} && $_[0]->{$_[1]}{_alias}{$actual}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $_[0]{$_[1]}{"_alias"} and $_[0]{$_[1]}{"_alias"}{$actual}
MC/DC0%0/2
exists $_[0]{$_[1]}{"_alias"} and $_[0]{$_[1]}{"_alias"}{$actual}
exists $_[0]{$_[1]}{"_alias"}
$_[0]{$_[1]}{"_alias"}{$actual}
Truth table33%1/3
A and B
A= exists $_[0]{$_[1]}{"_alias"}B= $_[0]{$_[1]}{"_alias"}{$actual}
| |||||||||||||||||||||||||||||
| 415 | 0 | ▶ | map { $_[0]->{$_[1]}{_alias}{$_}=$actual unless exists $_[0]->{$_[1]}{$_} } @types; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 28 | ▶ | $_[0]->{$_[1]}{'_attr'}{$actual}=$_[2] if $_[2]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =item load_singleBinary | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | Not done as I don't have example data yet. | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =cut | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | ▶ | sub load_singleBinary { | ||||||||||||||||||||||||||
|
Subroutine
load_singleBinary: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 428 | 0 | die "_singleBinary not done\n"; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | # sub setDefault { | ||||||||||||||||||||||||||||
| 433 | # $_[0]->{"_setDefault"}=$_[1] if exists $_[1]; | ||||||||||||||||||||||||||||
| 434 | # return $_[0]->{"_setDefault"} if exists $_[0]->{"_setDefault"}; | ||||||||||||||||||||||||||||
| 435 | # die ref($_[0]) . " does not have a default set to iterate\n"; | ||||||||||||||||||||||||||||
| 436 | # } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =back | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | For technical support please email to jlawrenc@cpan.org ... | ||||||||||||||||||||||||||||
| 443 | for faster service please include "Net::vFile" and "help" in your subject line. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | Jay J. Lawrence - jlawrenc@cpan.org | ||||||||||||||||||||||||||||
| 448 | Infonium Inc., Canada | ||||||||||||||||||||||||||||
| 449 | http://www.infonium.ca/ | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | Copyright (c) 2003 Jay J. Lawrence, Infonium Inc. All rights reserved. | ||||||||||||||||||||||||||||
| 454 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 455 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 458 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | Net::iCal - whose loading code inspired me for mine | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | RFC 2426, Net::iCal | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | =cut | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 5 | 1; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||