Bigtop
view release on metacpan or search on metacpan
lib/Bigtop/Parser.pm view on Meta::CPAN
# Set them in Grammar.pm directly under the use Parse::RecDescent statement.
my $ident_counter = 0;
my $parser;
my %valid_keywords;
my %keyword_for;
#---------------------------------------------------------------------
# Methods which add and validate keywords in the grammar
#---------------------------------------------------------------------
sub add_valid_keywords {
my $class = shift;
my $type = shift;
my $caller = caller( 0 );
my %callers;
KEYWORD:
foreach my $statement ( @_ ) {
my $keyword = $statement->{keyword};
my $seen_it = $valid_keywords{ $type }{ $keyword };
$valid_keywords{ $type }{ $keyword }++;
next KEYWORD if ( defined $statement->{type}
and $statement->{type} eq 'deprecated' );
push @{ $keyword_for{ $type }{ $keyword }{ callers } }, $caller;
next KEYWORD if $seen_it;
push @{ $keyword_for{ $type }{ statements } }, $statement;
}
}
BEGIN {
Bigtop::Parser->add_valid_keywords(
Bigtop::Keywords->get_docs_for(
'config',
qw( engine template_engine plugins base_dir app_dir )
)
);
# register no_gen as a keyword for (almost) all block types
# sequence and table are not included since SQL happens all at once
foreach my $keyword_type qw( app controller method ) {
Bigtop::Parser->add_valid_keywords(
Bigtop::Keywords->get_docs_for(
$keyword_type,
'no_gen',
)
);
}
# to allow a table to be described, but to be omitted from either
# a Model or SQL output
Bigtop::Parser->add_valid_keywords(
Bigtop::Keywords->get_docs_for( 'table', 'not_for' )
);
Bigtop::Parser->add_valid_keywords(
Bigtop::Keywords->get_docs_for( 'field', 'not_for' )
);
}
sub is_valid_keyword {
my $class = shift;
my $type = shift;
my $keyword = shift;
return $valid_keywords{$type}{$keyword};
}
sub get_valid_keywords {
my $class = shift;
my $type = shift;
my %trailer_for = (
config => 'or a valid backend block',
app => 'or a valid block (controller, sequence, ' .
'config, table, or join_table)',
controller => 'or a valid method block',
table => 'or a valid field block',
);
my %extras_for = (
app => [ 'literal' ],
);
my @extra_expected = @{ $extras_for{ $type } }
if ( defined $extras_for{ $type } );
my $trailer = $trailer_for{ $type };
my @expected = sort @extra_expected, keys %{ $valid_keywords{ $type } };
push( @expected, $trailer ) if $trailer;
return @expected;
}
sub get_keyword_docs {
foreach my $type ( keys %keyword_for ) {
my @sorted = sort { $a->{ sort_order } <=> $b->{ sort_order } }
@{ $keyword_for{ $type }{ statements } };
$keyword_for{ $type }{ statements } = \@sorted;
}
return \%keyword_for;
}
#---------------------------------------------------------------------
# The ident factory
#---------------------------------------------------------------------
sub get_ident {
$ident_counter++;
return "ident_$ident_counter";
}
lib/Bigtop/Parser.pm view on Meta::CPAN
Thus,
engine MP13;
becomes something like this:
use Framework qw/ engine=MP13 /;
in the base level controller. Both Catalyst and Gantry expect this
syntax.
The available engines depend on what the framework supports. The one
in the example is mod_perl 1.3 in the syntax of Catalyst and Gantry.
=item template_engine
Similar to engine, this specifies the template engine. Choices almost always
include TT, but might also include Mason or other templaters depending on
what your framework supports..
=back
=head1 Other KEYWORDS
=over 4
=item literal
This keyword applies to many backends at the app level and at some other
levels. This keyword is special, because it expects a type keyword
immediately before its values. For example:
literal SQL `CREATE...`;
It always instructs someone (the backend of type SQL in the example) to
directly insert the backquoted string into its output, without so much as
adjusting whitespace.
Backend types that should obey this statement are:
SQL - for backends of type SQL
Location - for backends constructing apache confs or the like
The literal Location statement may also be used at the controller level.
=item no_gen
Applies to backend blocks in the config block, app blocks, controller
blocks, and method blocks.
gen_from_string enforces the app level no_gen. If it has a true value
only a warning is printed, nothing is generated. None of the backends
are called.
gen_from_string also enforces no_gen on entire backends, if their config
block has a true no_gen value.
The Control backend of your choice is responsible for enforcing no_gen
at the controller and method levels.
=item not_for
Applies to tables and fields (although the latter only worked for Models
at the time of this writing).
Each backend is responsible for enforcing not_for. It should mean
that the field or table is ignored by the named backend type. Thus
table skip_model {
not_for Model;
}
should generate as normal in SQL backends, but should be completely
ignored for Models. The same should hold for fields marked not_for.
But my SQL backends didn't do that when I wrote this, only the Models
worked.
=back
=head1 METHODS
=over 4
=item get_keyword_docs
Called by TentMaker, so it can display the backend comments to the user
through their browser.
Returns: a hash reference of keyword docs understood by tentmaker's
templates.
=item gen_mode
Used internally.
Get accessor for whether we are really generating, or just serving tentmaker.
If we are not generating, there is no need to set up the templates for
all the backends.
=item set_gen_mode
Used internally.
Set accessor for whether we are really generating.
=item get_ident
Returns: the next available ident (as ident_n).
=item get_parser
Used internally.
Accessor to ensure that only one parser is ever instantiated.
=item load_backends
Used internally.
Responsible for loading all needed backends.
=item preprocess
Used internally.
Strips comment lines.
Returns: a hash keyed by line number, storing the comment on that line
before it was stripped..
=back
=head1 AUTHOR
( run in 2.090 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )