NAME

MacOSX::File - Get (HFS) File Attributes

SYNOPSIS

use MacOSX::File::Info;
$finfo = MacOSX::File::Info->get($path);
$finfo->type('TEXT');
$finfo->creator('ttxt');
$finfo->flags(-invisible => 1);
$finfo->set;

DESCRIPTION

This module implements what /Developer/Tools/{GetFileInfo,SetFile} does within perl.

EXPORT

Subs: getfinfo(), setfinfo()

fdFlags Constants: kIsAlias, kIsInvisible, kHasBundle, kNameLocked, kIsStationery, kHasCustomIcon, kHasBeenInited, kHasNoINITs, kIsShared, kIsHiddenExtention, kIsOnDesk,

nodeFlags Constants: kFSNodeLockedMask, kFSNodeResOpenMask, kFSNodeDataOpenMask, kFSNodeIsDirectoryMask, kFSNodeCopyProtectMask, kFSNodeForkOpenMask

DateTimeUtils.h

METHODS

$finfo = MacOSX::File::Info->get($path);
$finfo = getfileinfo($path);

Constructs MacOSX::File::Info from which you can manipulate file attributes. On failure, it returns undef and $MacOSX::File::OSErr is set.

$finfo->set([$path]);
setfinfo($finfo, [$path]);

Sets file attributes of file $path. If $path is omitted the file you used to construct $finfo is used. On success, it returns 1. On failure, it returns 0 and $MacOSX::File::OSErr is set.

Remember any changes to $finfo will not be commited until you call these functions.

ex)
  setfinfo(getfinfo("foo"), "bar"); 
  #Copies file attributes from foo to bar
$finfo->ref(), $finfo->nodeFlags(),

returns FSRef and nodeFlags of the file. these attributes are read only. Use of these methods are unlikely except for debugging purpose.

$finfo->type([$type]), $finfo->creator([$creator])

Gets and sets file type and creator, respectively. Though they accept strings longer than 4 bytes, only the first 4 bytes are used.

$finfo->ctime($ctime), $finfo->mtime($mtime)

Gets and sets file creation time and content modification time, respectively.

ex)
  $finfo->mtime(time());

Time is specified by seconds passed since Unix Epoch, January 1, 1970 00:00:00 UTC. Beware this is different from Native Macintosh Epoch, January 1, 1904, 00:00:00 UTC. I made it that way because perl on MacOSX uses Unix notion of Epoch. (FYI MacPerl uses Mac notion of Epoch).

These methods accept fractional numbers since Carbon supports it. It also accepts numbers larger than UINT_MAX for the same reason.

$finfo->fdflags($fdflags)

Gets and sets fdflags values. However, the use of this method is discouraged unless you are happy with bitwise operation. Use $finfo->flags method instead.

ex)
  $finfo->fdflags($finfo->fdflags | kIsInvisible)
  # makes the file invisible
$flags = $finfo->flags($attributes), %flags = $finfo->flags(%attributes)

Gets and sets fdflags like /Developer/Tools/SetFile. You can use SetFile-compatible letter notation or more intuitive args-by-hash notation.

When you use Attribute letters and corresponding swithes as follows. Uppercase to flag and lowercase to flag.

Letter Hash key         Description
-----------------------------------
[Aa]   -alias           Alias file
[Vv]   -invisible       Invisible*
[Bb]   -bundle          Bundle
[Ss]   -system          System (name locked)
[Tt]   -stationery      Stationary
[Cc]   -customicon      Custom icon*
[Ll]   -locked          Locked
[Ii]   -inited          Inited*
[Nn]   -noinit          No INIT resources
[Mm]   -shared          Shared (can run multiple times)
[Ee]   -hiddenx         Hidden extension*
[Dd]   -desktop         Desktop*

Attributes with asterisk can be applied to folders and files. Any other can be applied to files only.

ex)
  $attr = $finfo->flags("avbstclinmed"); 
  # unflag eveythinng
  $attr = $finfo->flags("L");
  # locks file with the rest of attributes untouched
  $attr = $finfo->flags(-locked => 1);
  # same thing but more intuitive

On scalar context, it returns attrib. letters. On list context, it returns hash notation shown above;

AUTHOR

Dan Kogai <dankogai@dan.co.jp>

SEE ALSO

MacPerl

COPYRIGHT

Copyright 2002 Dan Kogai <dankogai@dan.co.jp>

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

This modules uses MoreFiles of Apple Sample Code unchanged. http://developer.apple.com/samplecode/Sample_Code/Files/MoreFiles.htm

Copyright 1992-2001 Apple Computer, Inc. Portions copyright 1995 Jim Luther All rights reserved.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 124:

'=item' outside of any '=over'

Around line 393:

You forgot a '=back' before '=head1'