| 1 | package Inline::Mason::OO; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | our $VERSION = '0.02'; | |||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use AutoLoader; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Inline::Mason::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | our @EXPORT = qw(AUTOLOAD); | |||||||||
| 9 | 1 | our @ISA = qw(Inline::Mason::Base AutoLoader); | |||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Text::MicroMason qw(execute); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Inline::Files::Virtual; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 1 | our @files_to_load; | |||||||||
| 16 | 1 | ▶ | sub to_load_files { | ||||||||
|
Subroutine
to_load_files: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 1 | push @files_to_load, @_; | |||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | sub import { | ||||||||
|
Subroutine
import: called CC=4 SCAR=14.3
| |||||||||||
| 21 | 1 | shift; | |||||||||
| 22 | 1 | my $no_autoload; | |||||||||
| 23 | 1 | foreach my $arg (@_){ | |||||||||
| 24 | 1 | ▶ | $no_autoload = 1 if($arg eq 'no_autoload'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | } | ||||||||||
| 26 | 1 | ▶ | to_load_files((caller(0))[1]) unless $no_autoload; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 30 | 1 | my $pkg = shift; | |||||||||
| 31 | 1 | my @file = @_; | |||||||||
| 32 | 1 | my $self = bless {} => $pkg; | |||||||||
| 33 | 1 | foreach my $f (grep{$_} @files_to_load, (caller(0))[1], @file){ | |||||||||
| 34 | 1 | $self->load_file($f); | |||||||||
| 35 | } | ||||||||||
| 36 | 0 | $self; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub load_mason { | ||||||||
|
Subroutine
load_mason: not called CC=4 SCAR=25.0
Pod
documented
| |||||||||||
| 41 | 0 | my $self = shift; | |||||||||
| 42 | 0 | my %arg = @_; | |||||||||
| 43 | 0 | my ($pkg) = (caller(0))[0]; | |||||||||
| 44 | 1 | ▶ | no strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | 0 | ▶ | while(my($marker, $content) = each %arg){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | die err_taboo($marker) if $taboo_word{$marker}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | ▶ | $self->{template}{$marker} = $content if $content; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub load_file { | ||||||||
|
Subroutine
load_file: called CC=6 SCAR=32.2
Pod
documented
| |||||||||||
| 52 | 1 | my $self = shift; | |||||||||
| 53 | 1 | my $filename = shift; | |||||||||
| 54 | |||||||||||
| 55 | 1 | ▶ | my @virtual_filenames = vf_load($filename, $file_marker) or die; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | local $/; | |||||||||
| 57 | 0 | foreach my $vfile (@virtual_filenames){ | |||||||||
| 58 | 0 | my $marker = vf_marker($vfile); | |||||||||
| 59 | 0 | $marker =~ s/\n+//so; | |||||||||
| 60 | 0 | $marker =~ s/^__(.+?)__/$1/so; | |||||||||
| 61 | 0 | ▶ | die err_taboo($marker) if $taboo_word{$marker}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | ▶ | vf_open(my $F, $vfile) or die "$! ==> $marker"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | my $content = <$F>; | |||||||||
| 64 | 0 | ▶ | $self->load_mason($marker, $content) if $content; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | vf_close $F; | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub generate { | ||||||||
|
Subroutine
generate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | 0 | my $name = shift; | |||||||||
| 72 | 0 | my %args = @_; | |||||||||
| 73 | 0 | execute($template->{(caller(0))[0]}{$name}, %args); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 1 | my $self = shift; | |||||||||
| 78 | 1 | undef $self; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | sub AUTOLOAD{ | ||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=12.6
| |||||||||||
| 82 | 1 | ▶ | use vars '$AUTOLOAD'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 83 | 0 | $AUTOLOAD =~ /.+::(.+)/o; | |||||||||
| 84 | 0 | my $self = shift; | |||||||||
| 85 | 0 | my $pkg = (caller(0))[0]; | |||||||||
| 86 | 0 | ▶ | if(defined $self->{template}{$1}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | execute($self->{template}{$1}, @_); | |||||||||
| 88 | } | ||||||||||
| 89 | else { | ||||||||||
| 90 | 0 | die "${pkg}::$1 does not exist.\n"; | |||||||||
| 91 | } | ||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | 1 | 1; | |||||||||
| 96 | __END__ | ||||||||||