File Coverage

blib/lib/Inline/Mason.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Inline::Mason;
2              
3 3     3   81236 use strict;
  3         10  
  3         165  
4              
5             our $VERSION = '0.07';
6              
7 3     3   2259 use Inline::Mason::Base;
  3         8  
  3         449  
8 3     3   3789 use AutoLoader;
  3         5418  
  3         20  
9             our @EXPORT = qw(AUTOLOAD);
10             our @ISA = qw(Inline::Mason::Base AutoLoader);
11              
12 0           use Text::MicroMason qw(
13             execute
14             compile
15             execute_file
16             safe_execute
17             try_execute
18 3     3   7012 );
  0            
19             use Inline::Files::Virtual;
20              
21              
22             sub import {
23             shift;
24             my @ext_files;
25             my ($pkg, $script_name) = (caller(0))[0,1];
26              
27             foreach my $t (@_){
28             $as_subs->{$pkg} = 1 if $t eq 'as_subs';
29             $passive->{$pkg} = 1 if $t eq 'passive';
30             $use_oo->{$pkg} = 1 if $t eq 'OO';
31             @ext_files = @$t if ref($t) eq 'ARRAY';
32             }
33             return 1 if $passive->{$pkg};
34              
35             foreach my $real_file ($script_name, @ext_files){
36             load_file($real_file, $pkg);
37             }
38             }
39              
40             sub load_mason {
41             my %arg = @_;
42             my ($pkg) = (caller(0))[0];
43             no strict;
44             while(my($marker, $content) = each %arg){
45             die err_taboo($marker) if $taboo_word{$marker};
46             unless( defined $template->{$pkg}{$marker} ){
47             $template->{$pkg}{$marker} = $content;
48             }
49             *{"${pkg}::$marker"} = \&{"Inline::Mason::$marker"} if $as_subs->{$pkg};
50             }
51             }
52              
53             sub load_file {
54             my $filename = shift;
55             my $pkg = shift || (caller(0))[0];
56              
57             my @virtual_filenames = vf_load($filename, $file_marker);
58             local $/;
59             foreach my $vfile (@virtual_filenames){
60             my $marker = vf_marker($vfile);
61             $marker =~ s/\n+//so;
62             $marker =~ s/^__(.+?)__/$1/so;
63             die err_taboo($marker) if $taboo_word{$marker};
64             vf_open(my $F, $vfile) or die "$! ==> $marker";
65             my $content = <$F>;
66             next unless $content;
67             $template->{$pkg}{$marker} = $content;
68             no strict;
69             *{"${pkg}::$marker"} = \&{"Inline::Mason::$marker"} if $as_subs->{$pkg};
70             vf_close $F;
71             }
72             }
73              
74             sub generate {
75             my $name = shift;
76             my %args = @_;
77             execute($template->{(caller(0))[0]}{$name}, %args);
78             }
79              
80              
81             sub AUTOLOAD{
82             use vars '$AUTOLOAD';
83             $AUTOLOAD =~ /.+::(.+)/o;
84             my $pkg = (caller(0))[0];
85             if(defined $template->{$pkg}{$1}){
86             execute($template->{$pkg}{$1}, @_);
87             }
88             else {
89             die "${pkg}::$1 does not exist.\n";
90             }
91             }
92              
93              
94             1;
95             __END__