public
Description: A Camping-inspired Web Microframework for Perl
Homepage: http://groups.google.com/group/squatting-framework
Clone URL: git://github.com/beppu/squatting.git
Click here to lend your support to: squatting and make a donation at www.pledgie.com !
squatting / t / 02_view.t
100644 78 lines (65 sloc) 1.486 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use Test::More;
use strict;
use warnings;
 
{
  package Foo::Views;
  use Squatting ':views';
  use Data::Dump 'pp';
  our @V = (
    V(
      'html',
      layout => sub {
        my ($self, $v, @content) = @_;
        "( @content )";
      },
      home => sub {
        my ($self, $v) = @_;
        "$v->{title}";
      },
      _menu => sub {
        my ($self, $v) = @_;
        "1 2 3 4 5";
      },
      _ => sub {
        my ($self, $v) = @_;
        "$self->{template}";
      }
    )
  );
}
 
sub v {
  $Foo::Views::V[0]
}
 
our @tests = (
 
  sub {
    my $v = v;
    isa_ok($v, 'Squatting::View');
    return $v;
  },
 
  sub {
    my $v = v;
    can_ok($v, qw(name headers _render));
  },
 
  sub {
    my $v = v;
    my $body = $v->home({ title => 'home' });
    ok($body eq "( home )", '$v->home({ title => "home" }) should be wrapped by the layout.');
  },
 
  sub {
    my $v = v;
    my $body = $v->_menu({});
    ok($body eq "1 2 3 4 5", '$v->_menu({}) should NOT be wrapped by the layout.');
  },
 
  sub {
    my $v = v;
    my $body = $v->missing({});
    ok($body eq "( missing )", '$v->missing({}) should 1) invoke the _ template, 2) set $self->{template}, and 3) be wrapped by layout.');
  },
 
  sub {
    my $v = v;
    my $body = $v->_missing({});
    ok($body eq "_missing", '$v->_missing({}) should 1) invoke the _ template, 2) set $self->{template}, and 3) NOT be wrapped by layout.');
  },
 
);
 
plan tests => scalar(@tests);
 
for my $test (@tests) { $test->() }