« blib/lib/UR/Namespace/Command/Define/Datasource/Sqlite.pm
↑ Summary
blib/lib/UR/Object/View/Default/Gtk.pm »
| 1 | package UR::Object::Tag; | ||
| 2 | |||
| 3 | #TODO: update these to be UR::Value objects instead of some ancient hack | ||
| 4 | |||
| 5 | =pod | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | UR::Object::Tag - Transitory attribute tags for a UR::Object at a given time. | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | if (my @attribs = grep { $_->type eq 'invalid' } $obj->attribs()) { | ||
| 14 | print $obj->display_name . " has invalid attributes. They are:\n"; | ||
| 15 | for my $atrib (@attribs) { | ||
| 16 | print join(",",$attrib->properties) . ":" . $attrib->desc . "\n"; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | Project H_NHF00 has invalid attributes, they are: | ||
| 21 | project_subdirectory : Directory does not exist. | ||
| 22 | target, status : Target cannot be null for projects with an active status. | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | Objects of this class are created by create_attribs() on classes | ||
| 27 | derived from UR::Object. They are retrieved by | ||
| 28 | UR::Object->attribs(). | ||
| 29 | |||
| 30 | =head1 INHERITANCE | ||
| 31 | |||
| 32 | This class inherits from UR::ModuleBase. | ||
| 33 | |||
| 34 | =head1 OBJECT METHODS | ||
| 35 | |||
| 36 | =over 4 | ||
| 37 | |||
| 38 | =item type | ||
| 39 | |||
| 40 | A single-word description of the attribute which categorizes the | ||
| 41 | attribute. Common attribute types are: | ||
| 42 | |||
| 43 | =over 6 | ||
| 44 | |||
| 45 | =item invalid | ||
| 46 | |||
| 47 | Set when the object has invalid properties and cannot be saved. | ||
| 48 | |||
| 49 | =item changed | ||
| 50 | |||
| 51 | Set when the object is different than its "saved" version. | ||
| 52 | |||
| 53 | =item hidden | ||
| 54 | |||
| 55 | Set when the object has properties which should not be shown. | ||
| 56 | |||
| 57 | =item editable | ||
| 58 | |||
| 59 | Set when some part of the object is editable in the current context. | ||
| 60 | |||
| 61 | =item warning | ||
| 62 | |||
| 63 | Set when a warning about the state of the object is in effect. | ||
| 64 | |||
| 65 | =item match | ||
| 66 | |||
| 67 | Set when a search which is in effect matches this object's property(s). | ||
| 68 | |||
| 69 | =item comment | ||
| 70 | |||
| 71 | Set when this attribute is just an informational message. | ||
| 72 | |||
| 73 | =back | ||
| 74 | |||
| 75 | =item properties | ||
| 76 | |||
| 77 | A list of properties to which the attribute applies. This is null | ||
| 78 | when the attribute applies to the whole object, but typically returns | ||
| 79 | one property name. Occasionally, it returns more than one property. | ||
| 80 | Very rarely (currently never), the property may be in the form of an | ||
| 81 | arrayref like: [ class_name, id, property_name ], in which case the | ||
| 82 | property may actually be that of another related object. | ||
| 83 | |||
| 84 | =item desc | ||
| 85 | |||
| 86 | A string of text giving detail to the attribute. | ||
| 87 | |||
| 88 | =back | ||
| 89 | |||
| 90 | =head1 CLASS METHODS | ||
| 91 | |||
| 92 | =over 4 | ||
| 93 | |||
| 94 | =item create | ||
| 95 | |||
| 96 | Makes a new UR::Object::Tag. | ||
| 97 | |||
| 98 | =item delete | ||
| 99 | |||
| 100 | Throws one away. | ||
| 101 | |||
| 102 | =item filter | ||
| 103 | |||
| 104 | Sets/gets a filter to be applied to all attribute lists returned in | ||
| 105 | the application. This gives the application developer final veto | ||
| 106 | power over expressed attributes in the app. In most cases, developers | ||
| 107 | will write view components which use attributes, and will ignore | ||
| 108 | them rather than plug-in at this low level to augment/mangle/suppress. | ||
| 109 | |||
| 110 | The filter will be given an object reference and a reference to an | ||
| 111 | array of attributes which are tentatively to be delivered for the | ||
| 112 | object. | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | # set up package | ||
| 117 | require 5.006_000; | ||
| 118 | use warnings; | ||
| 119 | use strict; | ||
| 120 | our $VERSION = "0.46"; # UR $VERSION; | ||
| 121 | |||
| 122 | # set up module | ||
| 123 | use base qw(UR::ModuleBase); | ||
| 124 | our (@EXPORT, @EXPORT_OK); | ||
| 125 | @EXPORT = qw(); | ||
| 126 | @EXPORT_OK = qw(); | ||
| 127 | |||
| 128 | ##- use UR::Util; | ||
| 129 | |||
| 130 | our %default_values = | ||
| 131 | ( | ||
| 132 | type => undef, | ||
| 133 | properties => [], | ||
| 134 | desc => undef | ||
| 135 | ); | ||
| 136 | UR::Util->generate_readwrite_methods(%default_values); | ||
| 137 | |||
| 138 | *type_name = \&type; | ||
| 139 | *property_names = \&properties; | ||
| 140 | *description = \&description; | ||
| 141 | |||
| 142 | sub create($@) | ||
| 143 | { | ||
| 144 | my ($class, @initial_prop) = @_; | ||
| 145 | my $self = bless({%default_values,@initial_prop},$class); | ||
| 146 | if (not ref($self->{properties}) eq 'ARRAY') { | ||
| 147 | $self->{properties} = [ $self->{properties} ]; | ||
| 148 | } | ||
| 149 | return $self; | ||
| 150 | } | ||
| 151 | |||
| 152 | sub delete($) | ||
| 153 | { | ||
| 154 | UR::DeletedRef->bury($_[0]) | ||
| 155 | } | ||
| 156 | |||
| 157 | our $filter; | ||
| 158 | sub filter | ||
| 159 | { | ||
| 160 | if (@_ > 1) | ||
| 161 | { | ||
| 162 | my $old = $filter; | ||
| 163 | $filter = $_[1]; | ||
| 164 | return $old; | ||
| 165 | } | ||
| 166 | return $filter; | ||
| 167 | } | ||
| 168 | |||
| 169 | sub __display_name__ { | ||
| 170 | my $self = shift; | ||
| 171 | my $desc = $self->desc; | ||
| 172 | my $prefix = uc($self->type); | ||
| 173 | my @properties = map { "'$_'" } $self->properties; | ||
| 174 | my $prop_noun = scalar(@properties) > 1 ? 'properties' : 'property'; | ||
| 175 | my $msg = "$prefix: $prop_noun " . join(', ', @properties) . ": $desc"; | ||
| 176 | return $msg; | ||
| 177 | } | ||
| 178 | |||
| 179 | 1; | ||
| 180 | __END__ |