Canella

 view release on metacpan or  search on metacpan

lib/Canella/Context.pm  view on Meta::CPAN

    my $tempfile = File::Temp->new();
    print $tempfile <<EOM;
=encoding utf-8

=head1 NAME

Documentation For Deploy File '@{[$self->config]}'

=head1 SYNOPSIS

EOM

    if (my $synopsis = $self->docs->get('SYNOPSIS')) {
        print $tempfile $synopsis;
    } else {
        foreach my $task ($self->tasks->values) {
            print $tempfile <<EOM;
    canella -c @{[$self->config]} I<role> @{[$task->name]}
EOM
        }
    }

    print $tempfile <<EOM;

=head1 ROLES

EOM
    foreach my $role ($self->roles->values) {
        print $tempfile <<EOM;
=head2 @{[$role->name]}

EOM
    }

    print $tempfile <<EOM;

=head1 TASKS

EOM
    foreach my $task ($self->tasks->values) {
        print $tempfile <<EOM
=head2 @{[ $task->name ]}

@{[$task->description || '']}

EOM
    }

    foreach my $section (grep { !/^SYNOPSIS$/ } $self->docs->keys) {
        print $tempfile <<EOM
=head1 $section

@{[ $self->docs->get($section) ]}

EOM
    }

    print $tempfile "\n=cut\n";
    $tempfile->flush;

    local @ARGV = ('-F', $tempfile->filename);
    exit(Pod::Perldoc->run());
}

# Thread-specific stash
sub stash {
    my $self = shift;
    my $stash = $Coro::current->{Canella} ||= {};

    if (@_ == 0) {
        return $stash;
    }

    if (@_ == 1) {
        return $stash->{$_[0]};
    }

    while (my ($key, $value) = splice @_, 0, 2) {
        $stash->{$key} = $value;
    }
}

sub get_param {
    my ($self, $name) = @_;
    return $self->parameters->get($name);
}

sub set_param {
    my ($self, $name, $value) = @_;

    # If the same parameter has been overriden in the command line, respect
    # that instead of the actual parameter given
    if (defined(my $o_value = $self->override_parameters->get($name))) {
        return;
    }
    $self->parameters->set($name, $value);
}

sub get_role {
    $_[0]->roles->get($_[1]);
}

sub add_role {
    my ($self, $name, %args) = @_;

    if ($args{parameters}) {
        $args{parameters} = Hash::MultiValue->new(%{$args{parameters}});
    }

    $self->roles->set($name, Canella::Role->new(name => $name, %args));
}

sub get_task {
    $_[0]->tasks->get($_[1]);
}

sub add_task {
    my $self = shift;
    $self->tasks->set($_[0]->name, $_[0]);
}



( run in 1.437 second using v1.01-cache-2.11-cpan-4e7a2411597 )