use BSE::TB::Tags;
use BSE::TB::TagMembers;
-our $VERSION = "1.004";
+our $VERSION = "1.005";
=head1 NAME
Check that all of the specified tags are on the object.
+The array can contain either tag names or tag objects.
+
=cut
sub has_tags {
or return;
}
- $my_tag_ids{$tag->id}
+ $my_tag_ids{$work->id}
+ or return;
+ }
+
+ return 1;
+}
+
+=item has_tag($tag_name)
+
+=item has_tag($tag_object)
+
+Return true if the given tag can be found on the object.
+
+=cut
+
+sub has_tag {
+ my ($self, $tag) = @_;
+
+ unless (ref $tag) {
+ $tag = BSE::TB::Tags->getByName($self->tag_owner_type, $tag)
or return;
}
+ my @members = BSE::TB::TagMembers->getBy
+ (
+ owner_id => $self->id,
+ owner_type => $self->tag_owner_type,
+ tag_id => $tag->id,
+ );
+
+ @members
+ or return;
+
return 1;
}
#!perl -w
use strict;
use BSE::Test ();
-use Test::More tests => 38;
+use Test::More tests => 51;
use File::Spec;
use Carp qw(confess);
}
}
+{
+ my $error;
+ ok($parent->set_tags([ "SomeTag" ], \$error), "add SomeTag to parent");
+ ok($parent->has_tags([ "SomeTag" ]), "check true has_tags() by name");
+ my ($tag) = $parent->tag_objects;
+ is($tag->name, "SomeTag", "check tag_objects tag");
+ ok($parent->has_tags([ $tag ]), "check true has_tags() by object");
+ ok(!$parent->has_tags([ "Platform: iPad" ]), "check false has_tags() by name");
+ my $unknown = "Unknown: " . time();
+ ok(!$parent->has_tags([ $unknown ]),
+ "check false has_tags() by name (unknown tag)");
+ is_deeply([ $parent->tags ], [ "SomeTag" ], "tags() method");
+ my ($tag_id) = $parent->tag_ids;
+ is($tag_id, $tag->id, "check tag_ids");
+ my $by_name = $parent->tag_by_name("SomeTag");
+ is($by_name->id, $tag->id, "check tag_by_name()");
+ ok($parent->has_tag("SomeTag"), "check true has_tag() by name");
+ ok($parent->has_tag($tag), "check true has_tag() by object");
+ ok(!$parent->has_tag("Platform: iPad"), "check false has_tag() by name");
+ ok(!$parent->has_tag($unknown),
+ "check false has_tag() by name (unknown tag)");
+}
+
END {
for my $kid (@kids) {
$kid->remove($cfg);