OTRS-OPM-Installer
view release on metacpan or search on metacpan
lib/OTRS/OPM/Installer/Utils/File.pm view on Meta::CPAN
package OTRS::OPM::Installer::Utils::File;
$OTRS::OPM::Installer::Utils::File::VERSION = '0.05';
# ABSTRACT: File related utility functions
use v5.10;
use strict;
use warnings;
use File::HomeDir;
use File::Spec;
use File::Temp;
use HTTP::Tiny;
use HTTP::Tiny::FileProtocol;
use IO::All;
use Moo;
use OTRS::OPM::Installer::Logger;
use OTRS::OPM::Installer::Utils::Config;
use OTRS::OPM::Installer::Types;
use OTRS::Repository;
use Regexp::Common qw(URI);
use Types::Standard qw(ArrayRef Str Bool);
our $ALLOWED_SCHEME = [ 'HTTP', 'file' ];
has repositories => ( is => 'ro', isa => ArrayRef[Str], default => \&_repository_list );
has package => ( is => 'ro', isa => Str, required => 1 );
has otrs_version => ( is => 'ro', isa => Str, required => 1 );
has version => ( is => 'ro', isa => Str );
has verbose => ( is => 'ro', isa => Bool );
has logger => ( is => 'ro', default => sub{ OTRS::OPM::Installer::Logger->new } );
has rc_config => ( is => 'ro', lazy => 1, default => \&_rc_config );
has conf => ( is => 'ro' );
sub list_available {
my $self = shift;
my @repositories = @{ $self->repositories || [] };
for my $repo_url ( @repositories ) {
$repo_url .= '/otrs.xml' if '/otrs.xml' ne substr $repo_url, -9;
}
my $repo = OTRS::Repository->new(
sources => \@repositories,
);
my $otrs_version = $self->otrs_version;
$otrs_version =~ s{\.\d+$}{};
return $repo->list(
otrs => $otrs_version,
details => 1,
);
}
sub resolve_path {
my ($self) = @_;
my $path;
my $package = $self->package;
if ( $self->_is_url( $package ) ) {
# download file
$path = $self->_download( $package );
}
elsif ( -f $package ) {
# do nothing, file already exists
$path = $package;
}
else {
my @repositories = @{ $self->repositories || [] };
for my $repo ( @repositories ) {
$repo .= '/otrs.xml' if '/otrs.xml' ne substr $repo, -9;
}
say "Searching these repositories: @repositories" if $self->verbose;
my $repo = OTRS::Repository->new(
sources => \@repositories,
);
my ($otrs) = $self->otrs_version =~ m{\A(\d+\.\d+)};
my ($url) = $repo->find(
( run in 2.110 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )