The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SVG::Metadata - Perl module to capture metadata info about an SVG file

SYNOPSIS

use SVG::Metadata;

$svgmeta->parse($filename) 
    or die "Could not parse $filename: " . $svgmeta->errormsg();
$svgmeta2->parse($filename2)
    or die "Could not parse $filename: " . $svgmeta->errormsg();

# Do the files have the same metadata (author, title, license)?
if (! $svgmeta->compare($svgmeta2) ) {
   print "$filename is different than $filename2\n";
}

if ($svgmeta->title() eq '') {
    $svgmeta->title('Unknown');
}

if ($svgmeta->author() eq '') {
    $svgmeta->author('Unknown');
}

if ($svgmeta->license() eq '') {
    $svgmeta->license('Unknown');
}

if (! $svgmeta->keywords()) {
    $svgmeta->addKeyword('unsorted');
} elsif ($svgmeta->hasKeyword('unsorted') && $svgmeta->keywords()>1) {
    $svgmeta->removeKeyword('unsorted');
}

print $svgmeta->to_text();

DESCRIPTION

This module provides a way of extracting, browsing and using RDF metadata embedded in an SVG file.

FUNCTIONS

new

Creates a new SVG::Metadata object. Optionally, can pass in arguments 'title', 'author', and/or 'license'.

errormsg

Returns the last encountered error message. Most of the error messages are encountered during file parsing.

parse

Extracts RDF metadata out of an existing SVG file.

$svgmeta->parse($filename) || die "Error: " . $svgmeta->errormsg();

This routine looks for a field in the rdf:RDF section of the document named 'ns:Work' and then attempts to load the following keys from it: 'dc:title', 'dc:rights'->'ns:Agent', and 'ns:license'. If any are missing, it

Returns undef if there was a problem parsing the file, and sets an error message appropriately. The conditions under which it will return undef are as follows: No 'filename' parameter given

title

Gets or sets the title.

$svgmeta->title('My Title');
print $svgmeta->title();

author

Gets or sets the author.

$svgmeta->author('Bris Geek');
print $svgmeta->author();

license

Gets or sets the license.

$svgmeta->license('Public Domain');
print $svgmeta->license();

keywords

Gets or sets an array of keywords

addKeywords

Adds one or more a new keywords

$svgmeta->addKeyword('Fruit');
$svgmeta->addKeyword('Fruit','Vegetable','Animal','Mineral');

removeKeyword

Removes a given keyword

Return value: The keyword removed.

hasKeyword

Returns true if the metadata includes the given keyword

compare

Compares this metadata to another metadata for equality.

Two SVG file metadata objects are considered equivalent if they have exactly the same author, title, and license. Keywords can vary, as can the SVG file itself.

to_text

Creates a plain text representation of the metadata, suitable for debuggery, emails, etc.

Return value is a string containing the title, author, license, and keywords, each value on a separate line.

AUTHOR

Bryce Harrington <bryce@bryceharrington.com>

SEE ALSO

perl, XML::Simple