App-Sqitch

 view release on metacpan or  search on metacpan

lib/App/Sqitch/Target.pm  view on Meta::CPAN

    default  => sub {
        my $self = shift;
        $self->_fetch('client') || do {
            my $client = $self->engine->default_client;
            return $client unless App::Sqitch::ISWIN;
            return $client if $client =~ /[.](?:exe|bat)$/;
            return $client . '.exe';
        };
    },
);

has plan_file => (
    is       => 'ro',
    isa      => File,
    lazy     => 1,
    default => sub {
        my $self = shift;
        if ( my $f = $self->_fetch('plan_file') ) {
            return file $f;
        }
        return $self->top_dir->file('sqitch.plan')->cleanup;
    },
);

has plan => (
    is       => 'ro',
    isa      => Plan,
    lazy     => 1,
    default  => sub {
        my $self = shift;
        App::Sqitch::Plan->new(
            sqitch => $self->sqitch,
            target => $self,
        );
    },
);

has top_dir => (
    is      => 'ro',
    isa     => Dir,
    lazy    => 1,
    default => sub {
        my $self = shift;
        dir $self->_fetch('top_dir') || ();
    },
);

has reworked_dir => (
    is      => 'ro',
    isa     => Dir,
    lazy    => 1,
    default => sub {
        my $self = shift;
        if ( my $dir = $self->_fetch('reworked_dir') ) {
            return dir $dir;
        }
        $self->top_dir;
    },
);

for my $script (qw(deploy revert verify)) {
    has "$script\_dir" => (
        is      => 'ro',
        isa     => Dir,
        lazy    => 1,
        default => sub {
            my $self = shift;
            if ( my $dir = $self->_fetch("$script\_dir") ) {
                return dir $dir;
            }
            $self->top_dir->subdir($script)->cleanup;
        },
    );
    has "reworked_$script\_dir" => (
        is      => 'ro',
        isa     => Dir,
        lazy    => 1,
        default => sub {
            my $self = shift;
            if ( my $dir = $self->_fetch("reworked_$script\_dir") ) {
                return dir $dir;
            }
            if ( my $dir = $self->_fetch("$script\_dir") ) {
                return $self->reworked_dir->subdir($dir)->cleanup;
            }
            $self->reworked_dir->subdir($script)->cleanup;
        },
    );
}

has extension => (
    is      => 'ro',
    isa     => Str,
    lazy    => 1,
    default => sub {
        shift->_fetch('extension') || 'sql';
    },
);

sub BUILDARGS {
    my $class = shift;
    my $p = @_ == 1 && ref $_[0] ? { %{ +shift } } : { @_ };

    # Fetch params. URI can come from passed name.
    my $sqitch = $p->{sqitch} or return $p;
    my $name   = $p->{name} || $ENV{SQITCH_TARGET} || '';
    my $uri    = $p->{uri};

    # If we have a URI up-front, it's all good.
    if ($uri) {
        unless ($name) {
            # Set the URI as the name, sans password.
            if ($uri->password) {
                $uri = $uri->clone;
                $uri->password(undef);
            }
            $p->{name} = $uri->as_string;
        }
        return $p;
    }

lib/App/Sqitch/Target.pm  view on Meta::CPAN


  my $password = $target->password;

Returns the target password, if any. The password is looked up from the URI
or the C<$SQITCH_PASSWORD> environment variable.

=head3 C<engine>

  my $engine = $target->engine;

A L<App::Sqitch::Engine> object to use for database interactions with the
target.

=head3 C<registry>

  my $registry = $target->registry;

The name of the registry used by the database. The value comes from one of
these options, searched in this order:

=over

=item * C<--registry>

=item * C<target.$name.registry>

=item * C<engine.$engine.registry>

=item * C<core.registry>

=item * Engine-specific default

=back

=head3 C<client>

  my $client = $target->client;

Path to the engine command-line client. The value comes from one of these
options, searched in this order:

=over

=item * C<--client>

=item * C<target.$name.client>

=item * C<engine.$engine.client>

=item * C<core.client>

=item * Engine-and-OS-specific default

=back

=head3 C<top_dir>

  my $top_dir = $target->top_dir;

The path to the top directory of the project. This directory generally
contains the plan file and subdirectories for deploy, revert, and verify
scripts. The value comes from one of these options, searched in this order:

=over

=item * C<--top-dir>

=item * C<target.$name.top_dir>

=item * C<engine.$engine.top_dir>

=item * C<core.top_dir>

=item * F<.>

=back

=head3 C<plan_file>

  my $plan_file = $target->plan_file;

The path to the plan file. The value comes from one of these options, searched
in this order:

=over

=item * C<--plan-file>

=item * C<target.$name.plan_file>

=item * C<engine.$engine.plan_file>

=item * C<core.plan_file>

=item * F<C<$top_dir>/sqitch.plan>

=back

=head3 C<deploy_dir>

  my $deploy_dir = $target->deploy_dir;

The path to the deploy directory of the project. This directory contains all
of the deploy scripts referenced by changes in the C<plan_file>. The value
comes from one of these options, searched in this order:

=over

=item * C<--dir deploy_dir=$deploy_dir>

=item * C<target.$name.deploy_dir>

=item * C<engine.$engine.deploy_dir>

=item * C<core.deploy_dir>

=item * F<C<$top_dir/deploy>>

=back

=head3 C<revert_dir>

  my $revert_dir = $target->revert_dir;

The path to the revert directory of the project. This directory contains all
of the revert scripts referenced by changes the C<plan_file>. The value comes
from one of these options, searched in this order:

=over

=item * C<--dir revert_dir=$revert_dir>

=item * C<target.$name.revert_dir>

=item * C<engine.$engine.revert_dir>

=item * C<core.revert_dir>

=item * F<C<$top_dir/revert>>

=back

=head3 C<verify_dir>

  my $verify_dir = $target->verify_dir;

The path to the verify directory of the project. This directory contains all
of the verify scripts referenced by changes in the C<plan_file>. The value
comes from one of these options, searched in this order:

=over

=item * C<--dir verify_dir=$verify_dir>

=item * C<target.$name.verify_dir>

=item * C<engine.$engine.verify_dir>

=item * C<core.verify_dir>

=item * F<C<$top_dir/verify>>

=back

=head3 C<reworked_dir>

  my $reworked_dir = $target->reworked_dir;

The path to the reworked directory of the project. This directory contains
subdirectories for reworked deploy, revert, and verify scripts. The value
comes from one of these options, searched in this order:

=over

=item * C<--dir reworked_dir=$reworked_dir>

=item * C<target.$name.reworked_dir>

=item * C<engine.$engine.reworked_dir>

=item * C<core.reworked_dir>

=item * C<$top_dir>

=back

=head3 C<reworked_deploy_dir>

  my $reworked_deploy_dir = $target->reworked_deploy_dir;

The path to the reworked deploy directory of the project. This directory
contains all of the reworked deploy scripts referenced by changes in the
C<plan_file>. The value comes from one of these options, searched in this
order:

=over

=item * C<--dir reworked_deploy_dir=$reworked_deploy_dir>

=item * C<target.$name.reworked_deploy_dir>

=item * C<engine.$engine.reworked_deploy_dir>

=item * C<core.reworked_deploy_dir>

=item * F<C<$reworked_dir/reworked_deploy>>

=back

=head3 C<reworked_revert_dir>

  my $reworked_revert_dir = $target->reworked_revert_dir;

The path to the reworked revert directory of the project. This directory
contains all of the reworked revert scripts referenced by changes the
C<plan_file>. The value comes from one of these options, searched in this
order:

=over

=item * C<--dir reworked_revert_dir=$reworked_revert_dir>

=item * C<target.$name.reworked_revert_dir>

=item * C<engine.$engine.reworked_revert_dir>

=item * C<core.reworked_revert_dir>

=item * F<C<$reworked_dir/reworked_revert>>

=back

=head3 C<reworked_verify_dir>

  my $reworked_verify_dir = $target->reworked_verify_dir;

The path to the reworked verify directory of the project. This directory
contains all of the reworked verify scripts referenced by changes in the
C<plan_file>. The value comes from one of these options, searched in this
order:

=over

=item * C<--dir reworked_verify_dir=$reworked_verify_dir>

=item * C<target.$name.reworked_verify_dir>

=item * C<engine.$engine.reworked_verify_dir>

=item * C<core.reworked_verify_dir>

=item * F<C<$reworked_dir/reworked_verify>>

=back

=head3 C<extension>

  my $extension = $target->extension;

The file name extension to append to change names to create script file names.
The value comes from one of these options, searched in this order:

=over

=item * C<--extension>

=item * C<target.$name.extension>

=item * C<engine.$engine.extension>

=item * C<core.extension>

=item * C<"sql">

=back

=head3 C<variables>

  my $variables = $target->variables;

The database variables to use in change scripts. The value are merged from
these options, in this order:

=over

=item * C<target.$name.variables>

=item * C<engine.$engine.variables>

=back

The C<core.variables> configuration is not read, because command-specific
configurations, such as C<deploy.variables> and C<revert.variables> take
priority. The command themselves therefore pass them to the engine in the
proper priority order.

=head3 C<engine_key>

  my $key = $target->engine_key;

The key defining which engine to use. This value defines the class loaded by
C<engine>. Convenience method for C<< $target->uri->canonical_engine >>.

=head3 C<dsn>

  my $dsn = $target->dsn;

The DSN to use when connecting to the target via the DBI. Convenience method
for C<< $target->uri->dbi_dsn >>.

=head3 C<username>



( run in 0.525 second using v1.01-cache-2.11-cpan-5a3173703d6 )