1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
package Bio::DB::Tagger::Tag;
# $Id$
use Carp 'croak';
use overload
'""' => 'asString',
'cmp' => 'cmp',
fallback => 1;
=head1 NAME
Bio::DB::Tagger::Tag -- Authored tags
=head1 SYNOPSIS
use Bio::DB::Tagger::Tag;
my $tag = Bio::DB::Tagger::Tag->new(-name => 'venue',
-value => 'mermaid parade',
-author => 'lincoln.stein@gmail.com');
print $tag,"\n"; # use like a string
print $tag->name,"\n"; # object interface
print $tag->value,"\n"; # object interface
print $tag->author,"\n";
=head1 DESCRIPTION
This is a simple object tag interface that provides string-like
objects that have authors assigned to them. For use in attributing
tags to authors in the L<Bio::DB::Tagger> module.
=head2 METHODS
=over 4
=item $tag = Bio::DB::Tagger::Tag->new(-name=>$tag,
-author=>$author
[,-value=> $value,
,-modified=>$timestamp]);
Create a new tag with the indicated value and author.
=cut
sub new {
my $class = shift;
my %args = @_;
my $author = $args{-author} || '';
my $name = $args{-name};
my $value = $args{-value};
my $timestamp = $args{-modified};
croak "Usage: $class->new(-name=>'name' [,-value=>'tag value',-author=>'author'])"
unless defined $name;
return bless {
name => $name,
value => $value,
author => $author,
modified=>$timestamp,
},ref $class || $class;
}
=item $name = $tag->name
Return the tag's name.
=cut
sub name {
shift->{name};
}
=item $value = $tag->value;
Return the tag's value.
=cut
sub value {
shift->{value};
}
=item $timestamp = $tag->modified
Return the tag's modification timestamp.
=cut
sub modified {
shift->{modified};
}
=item $author = $tag->author;
Return the tag's author
=cut
sub author {
shift->{author};
}
=item $int = $tag->cmp($tag,$reversed)
Perform a string cmp() operation on another tag or a string.
If a string is provided, then operation is on tag name only.
If a tag is provided, then operation is on both tag and value.
=cut
sub cmp {
my $self = shift;
my ($other,$reversed) = @_;
my $name = $self->name;
my $value = $self->value;
my $result;
if (ref $other && $other->isa(__PACKAGE__)) {
my $other_name = $other->name;
my $other_value = $other->value;
$result = "${name}${value}" cmp "${other_name}${other_value}";
} else {
$result = $name cmp $other;
}
return $reversed ? -1*$result : $result;
}
=item $string = $tag->asString
Convert into a name:value string
=cut
sub asString {
my $self = shift;
return $self->name;
}
=back
=head1 SEE ALSO
L<Bio::DB::Tagger>
=head1 AUTHOR
Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
Copyright (c) 2009 Ontario Institute for Cancer Research
This package and its accompanying libraries is free software; you can
redistribute it and/or modify it under the terms of the GPL (either
version 1, or at your option, any later version) or the Artistic
License 2.0. Refer to LICENSE for the full license text. In addition,
please see DISCLAIMER.txt for disclaimers of warranty.
=cut
1;
__END__
|