Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions App-Nrepo/lib/App/Nrepo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ sub go {

$self->logger->log_and_croak(level => 'error', message => 'ERROR: action not supplied.') unless $action;

if ($action eq 'add-file'){
$self->add_file(@o)
}
elsif($action eq 'del-file'){
$self->del_file(@o)
}
elsif($action eq 'clean'){
my %actions;

$actions{'add-file'} = sub { $self->add_file(@o) };
$actions{'del-file'} = sub { $self->del_file(@o) };
$actions{'clean'} = sub {
%options = validate(
@o,
{
Expand All @@ -49,12 +47,10 @@ sub go {
else {
$self->clean(%options);
}
}
elsif($action eq 'init'){$self->init(@o)}
elsif($action eq 'list'){
$self->list();
}
elsif($action eq 'mirror'){
};
$actions{'init'} = sub { $self->init(@o) };
$actions{'list'} = sub { $self->list() };
$actions{'mirror'} = sub {
%options = validate(
@o,
{
Expand All @@ -74,8 +70,8 @@ sub go {
else {
$self->mirror(%options);
}
}
elsif($action eq 'tag'){
};
$actions{'tag'} = sub {
%options = validate(
@o,
{
Expand All @@ -87,6 +83,10 @@ sub go {
},
);
$self->tag(%options);
};

if ($actions{$action}) {
$actions{$action}->();
}
else {
$self->logger->log_and_croak(level => 'error', message => "ERROR: ${action} not supported.");
Expand Down
56 changes: 56 additions & 0 deletions App-Nrepo/lib/App/Nrepo/Logger.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/false

use strict;
use warnings;

package App::Nrepo::Logger;

# VERSION

my $logger;

sub load {
die "Already loaded!\n" if $logger;
my $package = shift;
$logger = shift;
return 1
}

sub new {
return $logger;
}

1;

__END__

=head1 NAME

App::Nrepo::Logger

=head1 SYNOPSIS

In bin/yourapp.pl

use App::Nrepo::Logger;
# do stuff
App::Nrepo::Logger->load($logobject);

Then in your lib/YourApp/Base.pm

use Moo;
use App::Nrepo::Logger;

has 'logger' => (
default => sub { App::Nrepo::Logger->new() },
);

=head1 METHODS

=head2 load($obj)

Saves $obj for later

=head2 new()

Returns $obj every time