Chapter 9
@keys = Gnome::MIME::get_keys("image/gif");
foreach $key (@keys) {
$value = Gnome::MIME::get_value("image/gif", $key);
print "$key => $value\n";
}
If your Perl sense isn't screaming hash by now, you might want to see a doctor! A
much better interface would be this one:
my $type_data = Gnome::MIME::type_data("image/gif");
while (($key, $value) = each %$type_data) {
print "$key => $value\n";
}
To provide this interface, you need to build a hash dynamically from the
results of calling gnome_mime_get_keys() and gnome_mime_get_value(). The full XSUB
used to support this interface is shown in Listing 9 7.
Listing 9 7. XSUB Implementing Gnome::MIME::type_data()
SV *
type_data(type)
const gchar * type
PREINIT:
GList *keys, *iter;
HV *hv;
SV *value;
char *key;
CODE:
// initialize hash
hv = newHV();
// get GList of keys for this type
keys = gnome_mime_get_keys(type);
// iterate through keys
for (iter = keys; iter; iter = iter >next) {
// get the key from the iterator
key = iter >data;
// create a new SV and load it with the value for this key
value = newSVpv(gnome_mime_get_value(type, key), 0);
226
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved