10 print "$t\n" . Dumper( OpenILS::Utils::TagURI->new( $t ) ) . "\n\n";
13 test_parser('TAG::stuff');
14 test_parser('tag::stuff');
15 test_parser('tag:open-ils.org:U2@acn/59521');
16 test_parser('tag:fulfillment2.esilibrary.com,2010:U2@bre/6866[1,2]');
17 test_parser('tag:x:U2@bre/6866[1,2]{bre,auri}/br1/2');
18 test_parser('tag:x:U2@bre/6866{bre,auri}/br1/2');
19 test_parser('tag:x:U2@bre/6866{bre,auri}');
20 test_parser('tag:x:U2@bre/6866/br1/2/some/extra/data');
21 test_parser('tag:x:U2@bre/6866/br1/2');
22 test_parser('tag:x:U2@bre/6866/br1');
23 test_parser('tag:x:biblio-record_entry/6866');
27 package OpenILS::Utils::TagURI;
30 sub DESTROY { } # keeps AUTOLOAD from catching inherent DESTROY calls
34 (my $field = $AUTOLOAD) =~ s/^.*://o;
37 return $obj->{$field} = shift;
39 return $obj->{$field};
48 $class = ref($class) || $class;
50 my $self = bless {} => $class;
51 $self->parse($tag) if ($tag);
58 $self = $self->new() unless (ref($self));
63 (warn("!! invalid tag uri: $tag\n") && return undef) unless ($tag =~ s/^tag:(?:([^:,]*),?([^:]*))://); # valid?
64 my ($host, $validity) = ($1, $2);
66 $self->validity($validity);
68 my ($classname, $id, $paging, $inc, $loc, $depth, $mods) = ($1, $2, $3, $4, $5, $6, $7)
72 (?:\[([^]]+)\])? # paging
73 (?:\{([^}]+)\})? # includes
74 (?:\/(\w+))? # location
76 (?:\/(.+))? # pathinfo
80 (warn("!! missing class ($classname) or id ($id) in uri: $tag\n") && return undef) if (!defined($classname) && !defined($id));
84 $self->data($classname);
86 if ($classname =~ /^U2\@/) {
87 $classname =~ s/^U2\@//;
91 $self->classname($classname);
93 $self->paging(($paging ? [ map { s/^\s*//; s/\s*$//; $_ } split(',', $paging) ] : []));
94 $self->includes(($inc? [ map { s/^\s*//; s/\s*$//; $_ } split(',', $inc) ] : []));
97 $self->pathinfo($mods);
100 $self->version($version);
106 my $parts = shift || {};
108 my $self = ref($class) ? $class : $class->new;
110 $self->$_($$parts{$_}) for keys %$parts;
111 return undef unless (defined($self->classname) && defined($self->id));
117 $tag .= ',' . $self->validity if ($self->validity);
122 $tag .= 'U2@' if ($self->version == 2);
123 $tag .= $self->classname . '/' . $self->id;
124 $tag .= '['. join(',', @{ $self->paging }) . ']' if defined($self->paging);
125 $tag .= '{'. join(',', @{ $self->includes }) . '}' if defined($self->includes);
126 $tag .= '/' . $self->location if defined($self->location);
127 $tag .= '/' . $self->depth if defined($self->depth);
128 $tag .= '/' . $self->pathinfo if defined($self->pathinfo);