Hyper-Developer
view release on metacpan or search on metacpan
lib/Hyper/Developer/Generator/Control/ContainerFlow.pm view on Meta::CPAN
{ if ( $item[1]->[0] eq 'this') {
shift @{$item[1]};
}
my $method = pop @{$item[1]};
'$self'
. (
@{$item[1]}
? '->get_value_recursive([qw('
. ( join q{ }, @{$item[1]} ) . ')])'
: q{}
) . "->$method()";
}
constant : m{[-]?\d[\d_]*(?: \.(?: \d[\d_])*)?}xms
| m{'(?: \\\\' | [^'] )* '}xms
| m{"(?: \\\\" | [^"] )* "}xms
variable : m{[a-z_][a-z0-9_]*}xmsi
variables : variable(s /\./)
ident : constant
| variables
{ if ( $item[1]->[0] eq 'this') {
shift @{$item[1]};
}
'$self'
. (
@{$item[1]}
? '->get_value_recursive([qw('
. ( join q{ }, @{$item[1]} ) . ')])'
: q{}
);
}
});
}
sub _create_action_code :RESTRICTED {
my $self = shift;
my $param = shift;
return q{} if ! defined $param;
my $parser = $self->_get_default_parser();
$parser->Extend(q{
terminator : m{ \s* ;* \s* (\#.*)? \z }xms
{ return q{} }
});
$parser->Replace(q{
expr : variables '=' mixed terminator
{ chomp $item{mixed};
$item{mixed} =~ s{\s*\;$}{};
"\$self->set_value_recursive("
. '[qw('
. ( join q{ }, @{$item{variables}} )
. ")], $item{mixed});"
}
| method
{ "$item{method};" }
});
# return input converted to grammar
my $result = eval {
join "\n", map { $parser->line($_) } split m{\n}, $param;
};
throw("$@ Error generating action code near\n$param") if $@;
return $result;
}
sub _create_condition_code :RESTRICTED {
my $self = shift;
my $param = shift;
return q{} if ! defined $param;
my $parser = $self->_get_default_parser();
$parser->Extend(q{
logop : 'eq' | 'ne' | '==' | '!=' | '||' | '&&' | 'or' | 'and'
});
$parser->Replace(q{
expr : mixed logop expr
{ join q{ }, @item[1..3] }
| mixed
});
# return input converted to grammar
my $result = eval {
join "\n", map { $parser->line($_); } split m{\n}, $param;
};
throw("$@ Error generating condition code near\n $param") if $@;
return $result;
}
1;
__END__
=pod
=head1 NAME
Hyper::Developer::Generator::Control::ContainerFlow - Abstract Base class with
code generation features
=head1 VERSION
This document describes Hyper::Developer::Generator::Control::ContainerFlow 0.01
=head1 DESCRIPTION
This class can handle two different Grammars.
See pod of Hyper::Control::Flow for more details.
=head2 Action grammar
The abstract action grammar in something like BNF notation looks like this.
Comments are perl style.
# lines have (optionsl) ; ends
<line> ::= <line_content> ";"
# line contains one of
<line_content> ::= <@identifier> "=" <constant> # a.b.c = "Foo";
| <@identifier>=<@identifier> # a.b.c = a;
| <method> # a.b = a.method();
# id trees may be used with . (like hashref trees in TT or HTC)
<@identifier> ::= <identifier> ( "." <identifier>)*
# single ids are alphanumeric
<identifier> ::= /\b[A-z0-9_]+\b/
# constants start with ', " or numbers
constant ::= ['"0-9].*
# methods are suffixed with ()
<method> ::= <@identifier> "()"
Examples:
# <@identifier> = <@identifier>
cSelectPerson.mRole = mInitiatorRole;
cSelectPerson = mInitiatorData.mInitiator;
# <@identifier> = <constant>
cSelectPerson.mRole = 'Superuser';
cSelectPerson.mRole = "Superuser";
( run in 0.795 second using v1.01-cache-2.11-cpan-71847e10f99 )