Dancer

 view release on metacpan or  search on metacpan

bin/dancer  view on Meta::CPAN

    my ($lib_file, $lib_path) = (pop @lib_path) . ".pm";
    $lib_path = join('/', @lib_path);
    $lib_path .= '/' if length $lib_path;
    return ($lib_file, $lib_path);
}

sub get_script_path {
    _dash_name(shift);
}

sub _dash_name {
    my $name = shift;
    $name =~ s/\:\:/-/g;
    $name;
}

sub create_node($;$) {
    my ($node, $root) = @_;
    $root ||= '.';

    my $manifest_name = catfile($root => 'MANIFEST');
    open my $manifest, ">", $manifest_name or die $!;

    # create a closure, so we do not need to get $root passed as
    # argument on _create_node
    my $add_to_manifest = sub {
        my $file = shift;
        $file =~ s{^$root/?}{};
        print $manifest "$file\n";
    };

    $add_to_manifest->($manifest_name);
    _create_node($add_to_manifest, $node, $root);
    close $manifest;
}

sub _create_node {
    my ($add_to_manifest, $node, $root) = @_;

    my $templates = templates($name);

    while ( my ($path, $content) = each %$node ) {
        $path = catfile($root, $path);

        if (ref($content) eq 'HASH') {
            safe_mkdir($path);
            _create_node($add_to_manifest, $content, $path);
        } elsif (ref($content) eq 'CODE') {
            # The content is a coderef, which, given the path to the file it
            # should create, will do the appropriate thing:
            $content->($path);
            $add_to_manifest->($path);
       } else {
            my $file = basename($path);
            my $dir  = dirname($path);
            my $ex = ($file =~ s/^\+//); # look for '+' flag (executable)
            my $template = $templates->{$file};

            $path = catfile($dir, $file); # rebuild the path without the '+' flag
            write_file($path, $template, {appdir => File::Spec->rel2abs($DANCER_APP_DIR)});
            chmod 0755, $path if $ex;
            $add_to_manifest->($path);
        }
    }
}

sub app_tree($) {
    my ($appname) = @_;

    return {
        "Makefile.PL"        => FILE,
        "MANIFEST.SKIP"      => FILE,
        lib                  => {
         $LIB_PATH => {
            $LIB_FILE => FILE,}
        },
        "bin" => {
            "+app.pl" => FILE,
        },
        "config.yml"         => FILE,
        "environments"       => {
            "development.yml" => FILE,
            "production.yml"  => FILE,
        },
        "views" => {
            "layouts"  => {"main.tt" => FILE,},
            "index.tt" => FILE,
        },
        "public" => {
            "+dispatch.cgi"  => FILE,
            "+dispatch.fcgi" => FILE,
            "404.html"       => FILE,
            "500.html"       => FILE,
            "css"            => {
                "style.css" => FILE,
                "error.css" => FILE,
            },
            "images"      => {
                "perldancer-bg.jpg" => \&write_bg,
                "perldancer.jpg" => \&write_logo,
            },
            "javascripts" => {
                "jquery.min.js" => FILE,
            },
            "favicon.ico" => \&write_favicon,
        },
        "t" => {
            "001_base.t"        => FILE,
            "002_index_route.t" => FILE,
        },
    };
}


sub safe_mkdir {
    my ($dir) = @_;
    if (not -d $dir) {
        print "+ $dir\n";
        mkpath $dir or die "could not mkpath $dir: $!";
    }
    else {



( run in 1.217 second using v1.01-cache-2.11-cpan-39bf76dae61 )