package Nephia::MetaTemplate; use strict; use warnings; use utf8; use Class::Accessor::Lite ( new => 0, rw => [qw[tag argument arrow oneliner replace_table]], ); sub new { my ($class, %opts) = @_; $opts{tag} ||= ''; $opts{arrow} ||= '}->{'; $opts{argument} ||= '$arg->{...}'; $opts{replace_table} ||= [qr|^| => '? my $arg = shift;'."\n"]; bless +{%opts}, $class; } sub process { my ($self, $instr) = @_; my $str = $instr; for my $tag ( ($str =~ m|(\[\= .*? \=\])|g) ) { my ($content) = $tag =~ m|\[\= (.*?) \=\]|; my $raw_content = $content; my $arrow = $self->{arrow}; $content =~ s|\.|$arrow|g; my $argument = $self->{argument}; $argument =~ s|\.\.\.|$content|; my $replace = $self->{tag}; $replace =~ s|\.\.\.|$argument|; $str =~ s|\[\= $raw_content \=\]|$replace|; } while ( $self->{replace_table}[0] && $self->{replace_table}[1] ) { my $search = shift(@{$self->{replace_table}}); my $replace = shift(@{$self->{replace_table}}); $str =~ s|$search|$replace|; } return $str; } 1; =head1 NAME Nephia::MetaTemplate - Meta Template Processor for Nephia::Setup flavors =head1 SYNOPSIS A template in your flavor. [= title =]

Access to value: [= title =]

Access to nested value: [= author.name =]

And, in your flavor class. my $meta_template = '...'; # meta template string my $mt = Nephia::MetaTemplate->new( tag => '{{ ... }}', arrow => '@', argument => 'val:...', replace_table => [ qr|| => '', ], ); my $template = $mt->process($meta_template); Then, $template is like as following. {{ val:title }}

Access to value: {{ val:title }}

Access to nested value: {{ val:author@name }}

=head1 DESCRIPTION Nephia::MetaTemplate is a Meta-Template Processor for helping you make your own nephia flavor. =head1 AUTHOR C Eytnobody@gmail.comE =cut