App-ZofCMS

 view release on metacpan or  search on metacpan

bin/zofcms_helper  view on Meta::CPAN

    show_plugins( @opts{qw/core  site/} );
    exit;
}

if ( $opts{plugins} ) {
    prepare_plugins( @opts{qw/core plugins  overwrite_existing_plugins/} );
}

if ( $opts{pages} ) {
    for my $page ( split /,/, $opts{pages} ) {
        my @dirs = split '/', $page;
        if ( @dirs > 1 ) {
            mkpath( [
                    File::Spec->catdir( $opts{core}, 'data', @dirs[0 .. $#dirs - 1] )
                ], 1, 0777
            );
            mkpath( [
                    File::Spec->catdir( $opts{core}, 'templates', @dirs[0 .. $#dirs - 1] )
                ], 1, 0777
            );
        }
        $dirs[-1] .= '.tmpl';
        my $data = File::Spec->catfile( $opts{core}, 'data', @dirs );

        my @template_dirs = @dirs;
        my $c = do( File::Spec->catfile( $opts{core}, 'config.txt' ) )
            or die "Failed to load config.txt $@ $!";

        if ( $c->{zcms_template_extension} ) {
            $template_dirs[-1] =~ s/\.tmpl/$c->{zcms_template_extension}/;
        }

        my $template = File::Spec->catfile(
                $opts{core}, 'templates', @template_dirs
        );

        if ( -e $data ) {
            print "$data file exists, omitting...\n";
        }
        else {
            my $fh_data;
            unless ( open $fh_data, '>', $data ) {
                warn "Failed to open $data [$!]\n";
            }
            else {
                close $fh_data;
            }
        }

        if ( -e $template ) {
            print "$template file exists, omitting...\n";
        }
        else {
            my $fh_template;
            unless ( open $fh_template, '>', $template ) {
                warn "Failed to open $template [$!]\n";
            }
            else {
                my $body_file = File::Spec->catfile( @dirs );
                my $title = join ' - ', map do { s/-(.)/ \u$1/g; $_ },
                    map ucfirst, grep length, reverse split m{/}, $page;

                print $fh_template <<"END";
use strict;
use warnings;

{
    body => \\'$body_file',
    title => '$title',
    plugins => [
    ],
};

__END__
END
                close $fh_template;
            }
        }
    }
}

exit
    if $opts{nocore};

@opts{ qw/index base index_tmpl index_html_tmpl 404  config_file/ } = (
    File::Spec->catfile( $opts{site}, 'index.pl' ),
    File::Spec->catfile( $opts{core}, 'data', 'base.tmpl' ),
    File::Spec->catfile( $opts{core}, 'templates', 'index.tmpl' ),
    File::Spec->catfile( $opts{core}, 'data', 'index.tmpl' ),
    File::Spec->catfile( $opts{core}, 'templates', '404.tmpl' ),
    File::Spec->catfile( $opts{core}, 'config.txt' ),
);

open my $fh, '>', $opts{index}
    or die "Failed to open/create $opts{index} [$!]";

print $fh make_index_pl( $opts{core} );
close $fh;
chmod 0755, $opts{index};

open $fh, '>', $opts{base}
    or die "Failed to open/create $opts{base} [$!]";

print $fh make_base();

open $fh, '>', $opts{index_tmpl}
    or die "Failed to open/create $opts{index_tmpl} [$!]";

print $fh make_index_tmpl();


open $fh, '>', $opts{index_html_tmpl}
    or die "Failed to open/create $opts{index_html_tmpl} [$!]";

print $fh make_index_html_tmpl();


open $fh, '>', $opts{404}
    or die "Failed to open/create $opts{404} [$!]";

print $fh make_404();



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