| 1 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 2 | # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de> | ||||||||||||||||||||
| 3 | # File: GX/Script/Build.pm | ||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | package GX::Script::Build; | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use Config qw( %Config ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 12 | # Class setup | ||||||||||||||||||||
| 13 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | use GX::Class; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 2 | extends 'GX::Script'; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 2 | build; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 23 | # Class data | ||||||||||||||||||||
| 24 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | my %TEMPLATES; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 30 | # Public methods | ||||||||||||||||||||
| 31 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub load_template { | ||||||||||||||||||
|
Subroutine
load_template: not called CC=7 SCAR=37.9
Pod
undocumented
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||
| 36 | 0 | my $template_name = shift; | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | my $package = ref $self; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | ▶ | if ( ! $TEMPLATES{$package} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | my %templates; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | my $data = do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 0 | ▶ | defined *{"${package}::DATA"} && *{"${package}::DATA"}{'GLOB'}; | ||||||||||||||||||
|
Condition0%0/2
defined *{"${package}::DATA";} && *{"${package}::DATA";}{'GLOB'}
MC/DC0%0/1
defined *{"${package}::DATA";} && *{"${package}::DATA";}{'GLOB'}
defined *{"${package}::DATA";}
Truth table0%0/2
A
A= defined *{"${package}::DATA";}
| |||||||||||||||||||||
| 47 | } or return undef; | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | my $template_name; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | for ( <$data> ) { | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $line = $_; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | utf8::decode( $line ); | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | if ( $line =~ /^@@ (\w+)/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 0 | $template_name = $1; | |||||||||||||||||||
| 59 | 0 | $templates{$template_name} = ''; | |||||||||||||||||||
| 60 | 0 | next; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | ▶ | $template_name or next; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 0 | $templates{$template_name} .= $line; | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | $TEMPLATES{$package} = \%templates; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | return $TEMPLATES{$package}{$template_name}; | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 0 | ▶ | sub render_template { | ||||||||||||||||||
|
Subroutine
render_template: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||||
| 80 | 0 | my $template_name = shift; | |||||||||||||||||||
| 81 | 0 | my $template_parameters = shift; | |||||||||||||||||||
| 82 | 0 | my $output_file = shift; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | my $template = $self->load_template( $template_name ); | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | ▶ | if ( ! defined $template ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | die "Template \"$template_name\" does not exist"; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | ▶ | $template_parameters ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$template_parameters ||= {}
MC/DC0%0/1
$template_parameters ||= {}
$template_parameters
Truth table0%0/2
A
A= $template_parameters
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | $template_parameters->{'shebang'} ||= "#!$Config{perlpath}"; | ||||||||||||||||||
|
Condition0%0/2
$template_parameters->{"shebang"} ||= qq[#!$GX::Script::Build::Config{"perlpath"}]
MC/DC0%0/1
$template_parameters->{"shebang"} ||= qq[#!$GX::Script::Build::Config{"perlpath"}]
$template_parameters->{"shebang"}
Truth table0%0/2
A
A= $template_parameters->{"shebang"}
| |||||||||||||||||||||
| 93 | 0 | ▶ | $template_parameters->{'application_class'} ||= $self->application_class; | ||||||||||||||||||
|
Condition0%0/3
$template_parameters->{"application_class"} ||= $self->application_class
MC/DC0%0/2
$template_parameters->{"application_class"} ||= $self->application_class
$template_parameters->{"application_class"}
$self->application_class
Truth table0%0/3
A ||= B
A= $template_parameters->{"application_class"}B= $self->application_class
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | while ( my ( $key, $value ) = each %$template_parameters ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 0 | ▶ | next unless defined $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 0 | $key = quotemeta $key; | |||||||||||||||||||
| 98 | 0 | $template =~ s/\[% $key %\]/$value/eg; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | if ( defined $output_file ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 0 | utf8::encode( $template ); | |||||||||||||||||||
| 103 | 0 | return $self->create_file( $output_file, $template ); | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | return $template; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 2 | 1; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||