App-GHGen

 view release on metacpan or  search on metacpan

lib/App/GHGen/Generator.pm  view on Meta::CPAN


    known type   → { type => 'scalar' }   # YAML string
    unknown type → undef

=head3 FORMAL SPECIFICATION

    SupportedTypes ≔ { perl, node, python, rust, go, ruby, java, cpp, php, docker, static }

    generate_workflow : ℤ* → ℤ* ∪ { ⊥ }

    t ∈ SupportedTypes → generators[t]()    (non-empty YAML string)
    t ∉ SupportedTypes → ⊥                  (undef)

=cut

sub generate_workflow($type) {
    my %generators = (
        perl   => \&_generate_perl_workflow,
        node   => \&_generate_node_workflow,
        python => \&_generate_python_workflow,
        rust   => \&_generate_rust_workflow,
        go     => \&_generate_go_workflow,
        ruby   => \&_generate_ruby_workflow,
        java   => \&_generate_java_workflow,
        cpp    => \&_generate_cpp_workflow,
        php    => \&_generate_php_workflow,
        docker => \&_generate_docker_workflow,
        static => \&_generate_static_workflow,
    );

	return undef unless exists $generators{$type};
	return $generators{$type}->();
}

=head2 list_workflow_types()

Return a flat hash of all supported workflow types and their descriptions.

=head3 Purpose

Enumerate every type that C<generate_workflow> can handle, with a one-line
human-readable description for each.

=head3 Arguments

None.

=head3 Returns

A flat hash (not a reference) mapping type strings to description strings.
Contains exactly eleven entries: C<perl>, C<node>, C<python>, C<rust>,
C<go>, C<ruby>, C<java>, C<cpp>, C<php>, C<docker>, C<static>.

=head3 Side Effects

None.  Pure function.

=head3 Usage Example

    my %types = list_workflow_types();
    say "$_: $types{$_}" for sort keys %types;

=head3 API SPECIFICATION

=head4 Input

    # No parameters.

=head4 Output

    { type => 'hashref', keys => { '*' => { type => 'scalar' } } }

=head3 FORMAL SPECIFICATION

    list_workflow_types : → ℤ* → ℤ*

    result ≔ { t ↦ desc(t) ∣ t ∈ SupportedTypes }
    |result| = 11

=cut

sub list_workflow_types() {
    return (
        node   => 'Node.js/npm projects with testing and linting',
        python => 'Python projects with pytest and coverage',
        rust   => 'Rust projects with cargo, clippy, and formatting',
        go     => 'Go projects with testing and race detection',
        ruby   => 'Ruby projects with bundler and rake',
        perl   => 'Perl projects with cpanm, prove, and coverage',
        java   => 'Java projects with Maven or Gradle',
        cpp    => 'C++ projects with CMake',
        php    => 'PHP projects with Composer and PHPUnit',
        docker => 'Docker image build and push workflow',
        static => 'Static site deployment to GitHub Pages',
    );
}

# Private workflow generators

sub _generate_perl_workflow() {
	# Try to detect requirements from project
	my $reqs = detect_perl_requirements();

	# Use detected min version or default to 5.36
	my $min_version = $reqs->{min_version} // '5.36';

	# Generate custom workflow with detected settings
	return generate_custom_perl_workflow({
		min_perl_version => $min_version,
		max_perl_version => '5.40',
		os => ['macos-latest', 'ubuntu-latest', 'windows-latest'],
		enable_critic => 1,
		enable_coverage => 1,
	});
}

sub _generate_node_workflow() {
	return <<'YAML';
---
name: Node.js CI



( run in 2.364 seconds using v1.01-cache-2.11-cpan-9169edd2b0e )