| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Template::Plugin::Assert |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Template Toolkit plugin module which allows you to assert that |
|
7
|
|
|
|
|
|
|
# items fetches from the stash are defined. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# AUTHOR |
|
10
|
|
|
|
|
|
|
# Andy Wardley |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# COPYRIGHT |
|
13
|
|
|
|
|
|
|
# Copyright (C) 2008 Andy Wardley. All Rights Reserved. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
16
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
#============================================================================ |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Template::Plugin::Assert; |
|
21
|
1
|
|
|
1
|
|
6
|
use base 'Template::Plugin'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
461
|
|
|
22
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
21
|
|
|
24
|
1
|
|
|
1
|
|
5
|
use Template::Exception; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
505
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = 1.00; |
|
27
|
|
|
|
|
|
|
our $MONAD = 'Template::Monad::Assert'; |
|
28
|
|
|
|
|
|
|
our $EXCEPTION = 'Template::Exception'; |
|
29
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub load { |
|
32
|
1
|
|
|
1
|
1
|
1
|
my $class = shift; |
|
33
|
1
|
|
|
|
|
2
|
my $context = shift; |
|
34
|
1
|
|
|
|
|
3
|
my $stash = $context->stash; |
|
35
|
|
|
|
|
|
|
my $vmethod = sub { |
|
36
|
8
|
|
|
8
|
|
123
|
$MONAD->new($stash, shift); |
|
37
|
1
|
|
|
|
|
4
|
}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# define .assert vmethods for hash and list objects |
|
40
|
1
|
|
|
|
|
5
|
$context->define_vmethod( hash => assert => $vmethod ); |
|
41
|
1
|
|
|
|
|
3
|
$context->define_vmethod( list => assert => $vmethod ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
4
|
return $class; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
|
47
|
6
|
|
|
6
|
1
|
14
|
my ($class, $context, @args) = @_; |
|
48
|
|
|
|
|
|
|
# create an assert plugin object which will handle simple variable |
|
49
|
|
|
|
|
|
|
# lookups. |
|
50
|
6
|
|
|
|
|
46
|
return bless { _CONTEXT => $context }, $class; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
54
|
2
|
|
|
2
|
|
4
|
my ($self, @args) = @_; |
|
55
|
2
|
|
|
|
|
5
|
my $item = $AUTOLOAD; |
|
56
|
2
|
|
|
|
|
12
|
$item =~ s/.*:://; |
|
57
|
2
|
50
|
|
|
|
8
|
return if $item eq 'DESTROY'; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# lookup the named values |
|
60
|
2
|
|
|
|
|
14
|
my $stash = $self->{ _CONTEXT }->stash; |
|
61
|
2
|
|
|
|
|
9
|
my $value = $stash->dotop($stash, $item, \@args); |
|
62
|
|
|
|
|
|
|
|
|
63
|
2
|
50
|
|
|
|
8
|
if (! defined $value) { |
|
64
|
2
|
|
|
|
|
14
|
die $EXCEPTION->new( assert => "undefined value for $item" ); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
0
|
|
|
|
|
0
|
return $value; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
package Template::Monad::Assert; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
our $EXCEPTION = 'Template::Exception'; |
|
73
|
|
|
|
|
|
|
our $AUTOLOAD; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
|
76
|
8
|
|
|
8
|
|
15
|
my ($class, $stash, $this) = @_; |
|
77
|
8
|
|
|
|
|
158
|
bless [$stash, $this], $class; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
81
|
8
|
|
|
8
|
|
18
|
my ($self, @args) = @_; |
|
82
|
8
|
|
|
|
|
17
|
my ($stash, $this) = @$self; |
|
83
|
8
|
|
|
|
|
15
|
my $item = $AUTOLOAD; |
|
84
|
8
|
|
|
|
|
38
|
$item =~ s/.*:://; |
|
85
|
8
|
50
|
|
|
|
22
|
return if $item eq 'DESTROY'; |
|
86
|
|
|
|
|
|
|
|
|
87
|
8
|
|
|
|
|
35
|
my $value = $stash->dotop($stash, $item, \@args); |
|
88
|
|
|
|
|
|
|
|
|
89
|
8
|
50
|
|
|
|
22
|
if (! defined $value) { |
|
90
|
8
|
|
|
|
|
44
|
die $EXCEPTION->new( assert => "undefined value for $item" ); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
return $value; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |