+sub HasEntry {
+ my $self = shift;
+ my $value = shift;
+ my $large_content = shift;
+ return undef unless defined $value && length $value;
+
+ my %canon_value;
+ #TODO: this could cache and optimize a fair bit.
+ foreach my $item ( @{$self->ItemsArrayRef} ) {
+ my $cf = $item->CustomFieldObj;
+ my $args = $canon_value{ $cf->Type };
+ if ( !$args ) {
+ $args = { Content => $value, LargeContent => $large_content };
+ my ($ok, $msg) = $cf->_CanonicalizeValue( $args );
+ next unless $ok;
+ $canon_value{ $cf->Type } = $args;
+ }
+
+ if ( $cf->Type eq 'Select' ) {
+ # select is case insensitive
+ return $item if lc $item->Content eq lc $args->{Content};
+ }
+ else {
+ if ( ($item->_Value('Content') || '') eq $args->{Content} ) {
+ if ( defined $item->LargeContent ) {
+ return $item
+ if defined $args->{LargeContent}
+ && $item->LargeContent eq $args->{LargeContent};
+ }
+ else {
+ return $item unless defined $args->{LargeContent};
+ }
+ } elsif ( $item->LargeContent && $args->{Content} ) {
+ return $item if ($item->LargeContent eq $args->{Content});
+ }
+ }
+ }
+ return undef;
+}