Developer-Dashboard

 view release on metacpan or  search on metacpan

lib/Developer/Dashboard/SkillManager.pm  view on Meta::CPAN

package Developer::Dashboard::SkillManager;

use strict;
use warnings;

our $VERSION = '3.14';

use Cwd qw(realpath);
use File::Copy qw(copy);
use File::Path qw(make_path remove_tree);
use File::Spec;
use File::Basename qw(basename);
use File::Find qw(find);
use File::Temp qw(tempdir);
use Capture::Tiny qw(capture);
use JSON::XS qw(decode_json encode_json);
use Developer::Dashboard::PathRegistry;

# new()
# Creates a SkillManager instance to handle skill installation, updates, uninstalls.
# Input: none.
# Output: SkillManager object.
sub new {
    my ( $class, %args ) = @_;
    my $paths = $args{paths}
      || Developer::Dashboard::PathRegistry->new(
        home            => ( $ENV{HOME} || (getpwuid($>))[7] || $ENV{USERPROFILE} || die 'Missing home directory' ),
        workspace_roots => [],
        project_roots   => [],
      );

    return bless {
        paths    => $paths,
        progress => $args{progress},
    }, $class;
}

# install_progress_tasks()
# Returns the ordered task list shown for one dashboard skills install run.
# Input: none.
# Output: array reference of progress task hashes.
sub install_progress_tasks {
    return [
        { id => 'fetch_source',         label => 'Fetch skill source' },
        { id => 'prepare_layout',       label => 'Prepare skill layout' },
        { id => 'install_aptfile',      label => 'Install aptfile dependencies' },
        { id => 'install_apkfile',      label => 'Install apkfile dependencies' },
        { id => 'install_dnfile',       label => 'Install dnfile dependencies' },
        { id => 'install_brewfile',     label => 'Install brewfile dependencies' },
        { id => 'install_package_json', label => 'Install package.json dependencies' },
        { id => 'install_cpanfile',     label => 'Install cpanfile dependencies' },
        { id => 'install_cpanfile_local', label => 'Install cpanfile.local dependencies' },
        { id => 'install_ddfile',       label => 'Install ddfile dependencies' },
        { id => 'install_ddfile_local', label => 'Install ddfile.local dependencies' },
    ];
}

# install_progress_tasks_for_sources(@sources)
# Returns the ordered source-level task list shown for multi-skill install and
# bare update-all runs.
# Input: skill source strings in the order they will be installed.
# Output: array reference of progress task hashes.
sub install_progress_tasks_for_sources {
    my ( $class, @sources ) = @_;
    my @tasks;
    my $idx = 0;
    for my $source (@sources) {
        next if !defined $source || $source eq '';
        push @tasks, {
            id    => 'install_source_' . $idx,
            label => 'Install/update ' . $source,
        };
        $idx++;
    }
    return \@tasks;
}

# install($source)
# Installs or reinstalls a skill into the deepest participating DD-OOP-LAYERS
# skills root.
# Input: Git URL, shorthand GitHub skill name, owner/repo shorthand, or direct
# local checked-out repository path.
# Output: hash ref with success status and repo name.
sub install {
    my ( $self, $source ) = @_;
    return { error => 'Missing skill source' } if !$source;
    my $result = $self->_install_to_skills_root( $source, $self->{paths}->skills_root );



( run in 0.539 second using v1.01-cache-2.11-cpan-39bf76dae61 )