Jakob Voß > SeeAlso-Server-0.57 > SeeAlso::Identifier

Download:
SeeAlso-Server-0.57.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.46   Source   Latest Release: SeeAlso-Server-0.71

NAME ^

SeeAlso::Identifier - An identifier passed to a SeeAlso-Server

DESCRIPTION ^

The query to a SeeAlso (and other unAPI) server is just an identifier. By default an identifier is just a string but identifiers may also have special properties like checksums and canonical forms.

SeeAlso::Identifier models identifiers that are passed to and processed by a SeeAlso::Server and a SeeAlso::Source. To model more complex identifiers you can either derive a subclass of SeeAlso::Identifier or create a new identifier class with SeeAlso::Identifier::Factory.

METHODS ^

new ( [ $value ] )

Creates a new identifier. A value will be used to set the identifier value with the 'value' method with undef as default value. This implies that the 'parse' method is called for every new identifier.

value ( [ $value ] )

Get (and optionally set) the value of this identifier. If you provide a value (including undef), it will be passed to the 'parse' function and stringified afterwards to be used as the new identifier value.

canonical

Returns a normalized version of the identifier. For most identifiers the normalized version should be an absolute URI. The default implementation of this method just returns the full value, so if the 'value' method already does normalization, you do not have to implement 'canonical'.

normalized

Alias for the 'canonical' method. Do not override this method but 'canonical'!

as_string

Returns an identifier object as plain string which is the canonical form. Identifiers are also converted to plain strings automatically by overloading. This means you can use identifiers as plain strings in most Perl constructs.

hash

Return a compact form of this identifier that can be used for indexing. A usual compact form is the local part without namespace prefix or a hash value. The default implementation of this method returns the canonical form of the identifier.

indexed

Alias for the 'hash' method. Do not override this method but 'hash'!

valid

Returns whether this identifier is valid - which is the case for all non-empty strings. This method is automatically called by overloading to derive a boolean value from an identifier. This means you can use identifiers as boolean values in most Perl constructs. Please note that in contrast to default scalars the identifier value '0' is valid!

parse ( $value )

Parses a value to an identifier value of this class. This method should always return a string - but the return value is stringified anyway. In most cases this and/or the 'canonical' method are the only methods to override in a subclass of SeeAlso::Identifier.

This method can also be used as function. To allow the same in you subclasses' implementation, use the template:

sub parse { my $value = shift; $value = shift if ref($value) and scalar @_;

    # ... further processing of $value (validating and cleaning) ...

    return defined $value ? "$value" : "";
}

cmp ( $identifier )

Compare two identifiers. If the supplied value is not an identifier, it will be converted first. By default the canonical values are compared.

SEE ALSO

See URI for the more specific Uniform Resource Identifiers.

AUTHOR ^

Jakob Voss <jakob.voss@gbv.de>

LICENSE ^

Copyright (C) 2009 by Verbundzentrale Goettingen (VZG) and Jakob Voss

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: