Dan Kogai > MacOSX-File > MacOSX::File::Info

Download:
MacOSX-File-0.71.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  6
Open  1
View/Report Bugs
Module Version: 0.70   Source  

NAME ^

MacOSX::File::Info - Gets/Sets (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()

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
$clone = $finfo->clone;

Returns a cloned (deep-copied) object. Handy when you want to compare changes.

$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 ^

  L<MacPerl>
  F</Developer/Tools/GetFileInfo>
  F</Developer/Tools/SetFile>

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.

syntax highlighting: