AddressBook

 view release on metacpan or  search on metacpan

lib/AddressBook/Entry.pm  view on Meta::CPAN

New attributes are added with null values.  If the "defaults" parameter is specified,
new attributes are added with values as specified by the attribute "default" metadata
specified in the config file.

=cut

sub fill {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my %args = @_;
  unless ($args{db}) {croak "database type not specified in AddressBook::Entry::fill"}
  my (%add_hash,$value,$meta);
  foreach (values %{$self->{config}->{db2generic}->{$args{db}}}) {
    unless (exists $self->{attr}->{$_}) {
      if ($args{defaults}) {
	$meta = $self->{config}->getMeta(attr=>$_,db=>$args{db});
	$value = $meta->{default} || '';
      } else {
	$value = "";
      }
      $add_hash{$_} = $value;
    }
  }
  $self->add(attr=>\%add_hash);
}

=head2 chop

  $entry->chop

Removes null valued attributes from an Entry.

=cut

sub chop {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  my (@delete_list,@list,$key,$found,$i);
  foreach $key (keys %{$self->{attr}}) {
    $found = 0;
    @list=();
    for ($i=0;$i<=$#{$self->{attr}->{$key}};$i++) {
      if ($self->{attr}->{$key}->[$i] ne "") {
	$found=1;
	push @list,$self->{attr}->{$key}->[$i];
      }
    }
    @{$self->{attr}->{$key}} = @list;
    if (! $found) {
      push @delete_list, $key;
    }
  }
  $self->delete(attrs=>\@delete_list);
}

=head2 dump

    print $entry->dump

Returns the (cannonical) attribute names and values.  Primarily used for 
debugging purposes.

=cut

sub dump {
  my $self = shift;
  my $class = ref $self || croak "Not a method call";
  return map {"$_ -> ". join(", ", @{$self->{attr}->{$_}}). "\n"}
    keys %{$self->{attr}}
}
1;
__END__

=head1 AUTHOR

Mark A. Hershberger, <mah@everybody.org>
David L. Leigh, <dleigh@sameasiteverwas.net>

=head1 SEE ALSO

L<AddressBook>
L<AddressBook::Config>

=cut



( run in 0.816 second using v1.01-cache-2.11-cpan-8450f2e95f3 )