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