| 1 | # Build::Hopen::Gen - base class for hopen generators | ||
| 2 | package Build::Hopen::Gen; | ||
| 3 | use Build::Hopen; | ||
| 4 | use Build::Hopen::Base; | ||
| 5 | |||
| 6 | our $VERSION = '0.000008'; # TRIAL | ||
| 7 | |||
| 8 | use Class::Tiny qw(proj_dir dest_dir), { | ||
| 9 | architecture => '', | ||
| 10 | }; | ||
| 11 | |||
| 12 | use Path::Class (); | ||
| 13 | |||
| 14 | # Docs {{{1 | ||
| 15 | |||
| 16 | =head1 NAME | ||
| 17 | |||
| 18 | Build::Hopen::Gen - Base class for hopen generators | ||
| 19 | |||
| 20 | =head1 SYNOPSIS | ||
| 21 | |||
| 22 | The code that generates blueprints for specific build systems | ||
| 23 | lives under C<Build::Hopen::Gen>. L<Build::Hopen::Phase::Gen> calls modules | ||
| 24 | under C<Build::Hopen::Gen> to create the blueprints. Those modules must | ||
| 25 | implement the interface defined here. | ||
| 26 | |||
| 27 | =head1 ATTRIBUTES | ||
| 28 | |||
| 29 | =head2 proj_dir | ||
| 30 | |||
| 31 | (Required) A L<Path::Class::Dir> instance specifying the root directory of | ||
| 32 | the project. | ||
| 33 | |||
| 34 | =head2 dest_dir | ||
| 35 | |||
| 36 | (Required) A L<Path::Class::Dir> instance specifying where the generated output | ||
| 37 | (e.g., blueprint or other files) should be written. | ||
| 38 | |||
| 39 | =head1 FUNCTIONS | ||
| 40 | |||
| 41 | A generator (C<Build::Hopen::Gen> subclass) is a Visitor. | ||
| 42 | |||
| 43 | B<Note>: | ||
| 44 | The generator does not have access to L<Build::Hopen::G::Link> instances. | ||
| 45 | That lack of access is the primary distinction between Ops and Links. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | # }}}1 | ||
| 50 | |||
| 51 | =head2 visit_goal | ||
| 52 | |||
| 53 | Do whatever the generator wants to do with a L<Build::Hopen::G::Goal>. | ||
| 54 | For example, the generator may change the goal's C<outputs>. | ||
| 55 | By default, no-op. Usage: | ||
| 56 | |||
| 57 | $generator->visit_goal($goal); | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | sub visit_goal { } | ||
| 62 | |||
| 63 | =head2 visit_node | ||
| 64 | |||
| 65 | Do whatever the generator wants to do with a L<Build::Hopen::G::Node> that | ||
| 66 | is not a Goal (see L</visit_goal>). By default, no-op. Usage: | ||
| 67 | |||
| 68 | $generator->visit_node($node) | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | sub visit_node { } | ||
| 73 | |||
| 74 | =head2 finalize | ||
| 75 | |||
| 76 | Do whatever the generator wants to do to finish up. By default, no-op. | ||
| 77 | Is provided the L<Build::Hopen::G::DAG> instance as a parameter. Usage: | ||
| 78 | |||
| 79 | $generator->finalize(-phase=>$Phase, -graph=>$dag) | ||
| 80 | |||
| 81 | =cut | ||
| 82 | |||
| 83 | sub finalize { } | ||
| 84 | |||
| 85 | =head2 default_toolset | ||
| 86 | |||
| 87 | Returns the package stem of the default toolset for this generator. | ||
| 88 | Must be implemented by subclasses. | ||
| 89 | |||
| 90 | When a hopen file invokes C<use language "Foo">, hopen will load | ||
| 91 | C<< Build::Hopen::T::<stem>::Foo >>, where C<< <stem> >> is the return | ||
| 92 | value of this function. | ||
| 93 | |||
| 94 | As a sanity check, hopen will first try to load C<< Build::Hopen::T::<stem> >>, | ||
| 95 | so make sure that is a valid package. | ||
| 96 | |||
| 97 | =cut | ||
| 98 | |||
| 99 | sub default_toolset { ... } | ||
| 100 | |||
| 101 | =head2 also_require | ||
| 102 | |||
| 103 | Returns the names of the packages, if any, that should be loaded along with | ||
| 104 | this generator. | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | sub also_require { } | ||
| 109 | |||
| 110 | =head2 run_build | ||
| 111 | |||
| 112 | Runs the build tool for which this generator has created blueprint files. | ||
| 113 | |||
| 114 | =cut | ||
| 115 | |||
| 116 | sub run_build { | ||
| 117 | warn "This generator is not configured to run a build tool. Sorry!"; | ||
| 118 | } | ||
| 119 | |||
| 120 | =head2 BUILD | ||
| 121 | |||
| 122 | Enforces the required arguments. | ||
| 123 | |||
| 124 | =cut | ||
| 125 | |||
| 126 | sub BUILD { | ||
| 127 | my ($self, $args) = @_; | ||
| 128 | croak "Need a project directory (Path::Class::Dir)" | ||
| 129 | unless eval { $self->proj_dir->DOES('Path::Class::Dir') }; | ||
| 130 | croak "Need a destination directory (Path::Class::Dir)" | ||
| 131 | unless eval { $self->dest_dir->DOES('Path::Class::Dir') }; | ||
| 132 | } #BUILD() | ||
| 133 | |||
| 134 | 1; | ||
| 135 | __END__ |