App-CPAN-Changes

 view release on metacpan or  search on metacpan

lib/App/CPAN/Changes.pm  view on Meta::CPAN


    require CPAN::Changes;
    ($file, CPAN::Changes->load($file));
}

my %common_args = (
    file => {
        schema => 'str*', # XXX filename
        summary => 'If not specified, will look for file called '.
            'Changes/CHANGELOG/etc in current directory',
        cmdline_aliases => {f=>{}},
        tags => ['common'],
    },
);

$SPEC{check} = {
    v => 1.1,
    summary => 'Check for parsing errors in Changes file',
    args => {
        %common_args,
    },
};
sub check {
    my %args = @_;

    my ($file, $ch) = _parse($args{file});
    my @rels = $ch->releases;
    return [400, "No releases found"] unless @rels;

    [200, "OK"];
}

$SPEC{dump} = {
    v => 1.1,
    summary => 'Dump Changes as JSON structure',
    args => {
        %common_args,
    },
};
sub dump {
    my %args = @_;

    my ($file, $ch) = _parse($args{file});

    [200, "OK", $ch];
}

sub _serialize {
    my ($ch, $reverse) = @_;

    $ch->serialize(reverse => $reverse);
}

sub _write {
    my ($file, $ch, $reverse) = @_;

    my $tempfile = sprintf("%s.%05d.tmp", $file, rand()*65536);
    sysopen my($fh), $tempfile, O_WRONLY|O_CREAT|O_EXCL
        or die "Can't open temp file '$tempfile': $!";
    print $fh _serialize($ch, $reverse);
    rename $file, "$file.bak"
        or die "Can't move '$file' to '$file.bak': $!";
    rename $tempfile, $file
        or die "Can't move '$tempfile' to '$file': $!";
}

$SPEC{preamble} = {
    v => 1.1,
    summary => 'Get/set preamble',
    tags => ['write'],
    args => {
        %common_args,
        preamble => {
            summary => 'Set new preamble',
            schema => 'str*',
            pos => 0,
        },
    },
};
sub preamble {
    my %args = @_;

    my ($file, $ch) = _parse($args{file});

    if (defined $args{preamble}) {
        $ch->preamble($args{preamble});
        _write($file, $ch);
        [200, "OK"];
    } else {
        [200, "OK", $ch->preamble];
    }
}

$SPEC{release} = {
    v => 1.1,
    summary => 'Return information (JSON object dump) of a specific release',
    args => {
        %common_args,
        version => {
            schema => 'str*',
            req => 1,
            pos => 0,
        },
    },
};
sub release {
    my %args = @_;

    my ($file, $ch) = _parse($args{file});

    my $rel = $ch->release($args{version});

    [200, "OK", $rel];
}

$SPEC{add_release} = {
    v => 1.1,
    summary => 'Add a new release',
    tags => ['write'],
    args => {
        %common_args,
        version => {
            schema => 'str*',



( run in 1.488 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )