NAME
    Setup::File::Symlink - Setup symlink (existence, target)

VERSION
    version 0.16

SYNOPSIS
     use Setup::File::Symlink 'setup_symlink';

     # simple usage (doesn't save undo data)
     my $res = setup_symlink symlink => "/baz", target => "/qux";
     die unless $res->[0] == 200 || $res->[0] == 304;

     # perform setup and save undo data
     my $res = setup_symlink symlink => "/foo", target => "/bar",
                             -undo_action => 'do';
     die unless $res->[0] == 200 || $res->[0] == 304;
     my $undo_data = $res->[3]{undo_data};

     # perform undo
     my $res = setup_symlink symlink => "/symlink", target=>"/target",
                             -undo_action => "undo", -undo_data=>$undo_data;
     die unless $res->[0] == 200;

DESCRIPTION
    This module uses Log::Any logging framework.

    This module has Rinci metadata.

SEE ALSO
    Setup

    Setup::File

FUNCTIONS
  setup_symlink(%args) -> [status, msg, result, meta]
    Setup symlink (existence, target).

    On do, will create symlink which points to specified target. If symlink
    already exists but points to another target, it will be replaced with
    the correct symlink if replacesymlink option is true. If a file already
    exists, it will be removed (or, backed up to temporary directory) before
    the symlink is created, if replacefile option is true.

    On undo, will delete symlink if it was created by this function, and
    restore the original symlink/file/dir if it was replaced during do.

    Arguments ('*' denotes required arguments):

    *   create => *bool* (default: 1)

        Create if symlink doesn't exist.

        If set to false, then setup will fail (412) if this condition is
        encountered.

    *   replace_dir => *bool* (default: 0)

        Replace if there is existing dir.

        If set to false, then setup will fail (412) if this condition is
        encountered.

    *   replace_file => *bool* (default: 0)

        Replace if there is existing non-symlink file.

        If set to false, then setup will fail (412) if this condition is
        encountered.

    *   replace_symlink => *bool* (default: 1)

        Replace previous symlink if it already exists but doesn't point to
        the wanted target.

        If set to false, then setup will fail (412) if this condition is
        encountered.

    *   symlink* => *str*

        Path to symlink.

        Symlink path needs to be absolute so it's normalized.

    *   target* => *str*

        Target path of symlink.

    Return value:

    Returns an enveloped result (an array). First element (status) is an
    integer containing HTTP status code (200 means OK, 4xx caller error, 5xx
    function error). Second element (msg) is a string containing error
    message, or 'OK' if status is 200. Third element (result) is optional,
    the actual result. Fourth element (meta) is called result metadata and
    is optional, a hash that contains extra information.

AUTHOR
    Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE
    This software is copyright (c) 2012 by Steven Haryanto.

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

