The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WebShortcutUtil::Read - Utilities for reading web shortcut files

SYNOPSIS

  use WebShortcutUtil::Read qw(
        shortcut_has_valid_extension
        read_shortcut_file
        read_shortcut_file_url);

  # If the file does not have a valid shortcut extension, the reads will fail.
  if(!shortcut_has_valid_extension($filename)) {
          die "File is not a shortcut!";
  }

  # Read name and URL
  my $results = read_shortcut_file($filename);
  my $name = $results->{"name"};
  my $url = $results->{"url"};

  # Just get URL
  my $url = read_shortcut_file_url($filename);

DESCRIPTION

The following subroutines are provided:

shortcut_file_has_valid_extension( FILENAME )

Checks the specified file name and returns true if its extension matches one of the supported types.

read_shortcut_file( FILENAME )

Reads the specified file and extracts the contents. The type of shortcut file is determined by the file extension. A hash will be returned containing two keys: "name" and "url". The name is the name/title of the shortcut. A hash will always be returned - if there is an error reading the file, the routine will die with an appropriate error message.

For ".desktop" and ".url" files, the reader can handle unicode characters in the name and URL. ".webloc" files may contain unicode characters as well, although this functionality still requires more testing.

The name returned by the readers is a guess. Many shortcut files do not contain a name/title embedded in the file. ".desktop" shortcuts may contain several embedded names with different encodings. Unfortunately, these names are not necessarily updated when the shortcut is renamed. It is difficult, if not impossible, to determine which is the correct name. As of right now, the reader will always return the name of the file as the name of the shortcut, although this may change in the future.

Note: The Mac::PropertyList module (http://search.cpan.org/~bdfoy/Mac-PropertyList/) must be installed in order to read ".webloc" files.

read_shortcut_file_url( FILENAME )

The same as read_shortcut_file, but only returns a string containing the URL.

read_desktop_shortcut_file( FILENAME )
read_url_shortcut_file( FILENAME )
read_website_shortcut_file( FILENAME )
read_webloc_shortcut_file( FILENAME )

These routines operate essentially the same way as read_shortcut_file. However, they force the file to be parsed as a particular type, regardless of the file extension. These should be used sparingly. You should use read_shortcut_file unless you have a good reason not to.

read_desktop_shortcut_handle( HANDLE )
read_url_shortcut_handle( HANDLE )
read_website_shortcut_handle( HANDLE )
read_webloc_shortcut_handle( HANDLE )

These routines operate essentially the same way as read_shortcut_file. However, they force the file to be parsed as a particular type, regardless of the file extension. These should be used sparingly. You should use read_shortcut_file unless you have a good reason not to.

get_handle_reader_for_file( FILENAME )

These routines operate essentially the same way as read_shortcut_file. However, they force the file to be parsed as a particular type, regardless of the file extension. These should be used sparingly. You should use read_shortcut_file unless you have a good reason not to.

SEE ALSO

http://search.cpan.org/~beckus/WebShortcutUtil/lib/WebShortcutUtil.pm

COPYRIGHT AND LICENSE

Copyright (C) 2013 by Andre Beckus

This library is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language itself.