App-TemplateServer

 view release on metacpan or  search on metacpan

lib/App/TemplateServer.pm  view on Meta::CPAN

    foo: "bar"
    packages:
      Test:
        constructors: ["new"]
        methods:
          map_foo_bar:
            - ["foo"]
            - "bar"
            - ["bar"]
            - "foo"
            - "INVALID INPUT"
    instantiate:
      test_instance: "Test"
      another_test_instance:
        Test: "new"

This makes the variables C<foo>, C<test_instance>, and
C<another_test_instance> available in the templates.  It also creates
a package called C<Test> and adds a constructor called C<new>, and a
method called C<map_foo_bar> that returns "bar" when the argument is
"foo", "foo" when the argument is "bar", and "INVALID INPUT"
otherwise.

=head3 DESCRIPTION

Any key/value pair other than C<packages> and C<instantiate> is
treated as a literal variable to make available in the template.

C<packages> is passed to L<Package::FromData> and is used to
dynamically create data, methods, static methods, and constructors
inside packages.  See L<Package::FromData> for more details.

t/synopsis.t  view on Meta::CPAN


# due to laziness, the package Test doesn't exist now
ok !eval { Test->new }, 'no Test yet';

$serv->_data; # and now it's here

# first, test the created packages
isa_ok my $a = Test->new, 'Test', 'Test->new';
is $a->map_foo_bar('foo'), 'bar';
is $a->map_foo_bar('bar'), 'foo';
is $a->map_foo_bar(qw/foo gorch/), 'INVALID INPUT';

my $req = HTTP::Request->new(GET => '/foo');
my $res = $serv->_req_handler($req);
ok $res->content, 'got content';
my $result = eval 'my '. $res->content.'; $VAR1'; # yeck
ok $result, 'deserialized ok';

isa_ok $result->{another_test_instance}, 'Test', 'another_test_instance';
isa_ok $result->{test_instance}, 'Test', 'test_instance';

t/synopsis.t  view on Meta::CPAN

foo: "bar"
packages:
  Test:
    constructors: ["new"]
    methods:
      map_foo_bar:
        - ["foo"]
        - "bar"
        - ["bar"]
        - "foo"
        - "INVALID INPUT"
instantiate:
  test_instance: "Test"
  another_test_instance:
    Test: "new"



( run in 0.437 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )