App-QuoteCC

 view release on metacpan or  search on metacpan

lib/App/QuoteCC/Output/C.pm  view on Meta::CPAN

    my ($self) = @_;
    my $quotes = $self->quotes;
    my $template = $self->template;
    my $out;

    Template->new->process(
        \$template,
        {
            quotes => $quotes,
            size => scalar(@$quotes),
            escape => sub {
                my $text = shift;
                $text =~ s/"/\\"/g;
                my $was = $text;
                $text =~ s/\\(\$)/\\\\$1/g;
                given ($text) {
                    when (/\n/) {
                        return join(qq[\\n"\n], map { qq["$_] } split /\n/, $text). q["];
                    }
                    default {
                        return qq["$text"];

lib/App/QuoteCC/Output/C.pm  view on Meta::CPAN

__[ program ]__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>

const char* const quotes[[% size %]] = {
[% FOREACH quote IN quotes
%]    [% escape(quote) %],
[% END
%]};

/* returns random integer between min and max, inclusive */
const int rand_range(const int min, const int max)
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    const long int n = tv.tv_usec * getpid();
    srand(n);

lib/App/QuoteCC/Output/Lua.pm  view on Meta::CPAN

    my ($self) = @_;
    my $quotes = $self->quotes;
    my $template = $self->template;
    my $out;

    Template->new->process(
        \$template,
        {
            quotes => $quotes,
            size => scalar(@$quotes),
            escape => sub {
                my $text = shift;
                return "[===[$text]===]";
            },
        },
        \$out
    );

    return $out;
}

lib/App/QuoteCC/Output/Lua.pm  view on Meta::CPAN

=cut

__DATA__
__[ program ]__
#!/usr/bin/env lua

require 'posix'

local quotes = {[%
FOREACH quote IN quotes %]
    [% escape(quote) %],[%
END %]
}

if arg[1] == "--all" then
    print(table.concat(quotes, "\n"))
else
    local pid = posix.getpid("pid")
    local time = os.time();
    math.randomseed(time * pid)
    print(quotes[math.random(#quotes)])



( run in 0.334 second using v1.01-cache-2.11-cpan-c21f80fb71c )