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

VERSION
    version 0.19

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

DESCRIPTION
    This module has Rinci metadata.

FUNCTIONS
    None are exported by default, but they are exportable.

  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 replace*symlink option is true. If a file already
    exists, it will be removed (or, backed up to temporary directory) before
    the symlink is created, if replace*file 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.

    This function supports undo operation. This function supports dry-run
    operation. This function is idempotent (repeated invocations with same
    arguments has the same effect as single invocation). This function can
    use transactions.

    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.

    Special arguments:

    *   -dry_run => *bool*

        Pass -dry_run=>1 to enable simulation mode.

    *   -tx_action => *str*

        You currently can set this to 'rollback'. Usually you do not have to
        pass this yourself, Perinci::Access::InProcess will do it for you.
        For more details on transactions, see Rinci::function::Transaction.

    *   -tx_manager => *obj*

        Instance of transaction manager object, usually
        Perinci::Tx::Manager. Usually you do not have to pass this yourself,
        Perinci::Access::InProcess will do it for you. For more details on
        transactions, see Rinci::function::Transaction.

    *   -undo_action => *str*

        To undo, pass -undo_action=>'undo' to function. You will also need
        to pass -undo_data, unless you use transaction. For more details on
        undo protocol, see Rinci::function::Undo.

    *   -undo_data => *array*

        Required if you want undo and you do not use transaction. For more
        details on undo protocol, see Rinci::function::Undo.

    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.

