| 1 | package Template::Caribou; | ||||||||||
| 2 | 12 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: class-based HTML-centric templating system | ||||||||||
| 4 | 12 | $Template::Caribou::VERSION = '1.1.0'; | |||||||||
| 5 | 12 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 12 | ▶ | use Moose::Exporter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 12 | ▶ | use Template::Caribou::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 12 | ▶ | use Template::Caribou::Tags qw/ attr /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 12 | Moose::Exporter->setup_import_methods( | |||||||||
| 13 | with_meta => [ 'template' ], | ||||||||||
| 14 | as_is => [ 'attr', 'show' ], | ||||||||||
| 15 | also => [ 'Template::Caribou::Role' ], | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 12 | ▶ | use Moose::Util qw/ apply_all_roles /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 12 | ▶ | use 5.10.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | sub show { | ||||||||||
| 23 | 0 | ▶ | state $shown_warning = 0; | ||||||||
|
Subroutine
show: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | carp 'show() is deprecated, use $bou->my_template instead' | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | unless $shown_warning++; | ||||||||||
| 27 | |||||||||||
| 28 | 0 | $Template::Caribou::TEMPLATE->render(@_); | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | sub init_meta { | ||||||||||
| 32 | 15 | ▶ | my $class = shift; | ||||||||
|
Subroutine
init_meta: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 33 | 15 | my %args = @_; | |||||||||
| 34 | |||||||||||
| 35 | 15 | my $meta = eval { $args{for_class}->meta }; | |||||||||
| 36 | |||||||||||
| 37 | 15 | ▶ | unless ( $meta ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 11 | $meta = Moose->init_meta(@_); | |||||||||
| 39 | 11 | ▶ | eval "package $args{for_class}; use Moose;"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 15 | apply_all_roles( $args{for_class}, 'Template::Caribou::Role' ); | |||||||||
| 43 | |||||||||||
| 44 | 15 | return $meta; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 12 | 1; | |||||||||
| 48 | |||||||||||
| 49 | __END__ | ||||||||||
| 50 | |||||||||||
| 51 | =pod | ||||||||||
| 52 | |||||||||||
| 53 | =encoding UTF-8 | ||||||||||
| 54 | |||||||||||
| 55 | =head1 NAME | ||||||||||
| 56 | |||||||||||
| 57 | Template::Caribou - class-based HTML-centric templating system | ||||||||||
| 58 | |||||||||||
| 59 | =head1 VERSION | ||||||||||
| 60 | |||||||||||
| 61 | version 1.1.0 | ||||||||||
| 62 | |||||||||||
| 63 | =head1 SYNOPSIS | ||||||||||
| 64 | |||||||||||
| 65 | package MyTemplate; | ||||||||||
| 66 | |||||||||||
| 67 | use Template::Caribou; | ||||||||||
| 68 | |||||||||||
| 69 | use Template::Caribou::Tags::HTML qw/ :all /; | ||||||||||
| 70 | |||||||||||
| 71 | has name => ( is => 'ro' ); | ||||||||||
| 72 | |||||||||||
| 73 | template page => sub { | ||||||||||
| 74 | my $self = shift; | ||||||||||
| 75 | |||||||||||
| 76 | html { | ||||||||||
| 77 | head { | ||||||||||
| 78 | title { 'Example' } | ||||||||||
| 79 | }; | ||||||||||
| 80 | |||||||||||
| 81 | $self->my_body; | ||||||||||
| 82 | } | ||||||||||
| 83 | }; | ||||||||||
| 84 | |||||||||||
| 85 | template my_body => sub { | ||||||||||
| 86 | my $self = shift; | ||||||||||
| 87 | |||||||||||
| 88 | body { | ||||||||||
| 89 | h1 { 'howdie ' . $self->name } | ||||||||||
| 90 | } | ||||||||||
| 91 | }; | ||||||||||
| 92 | |||||||||||
| 93 | package main; | ||||||||||
| 94 | |||||||||||
| 95 | my $template = MyTemplate->new( name => 'Yanick' ); | ||||||||||
| 96 | print $template->page; | ||||||||||
| 97 | |||||||||||
| 98 | =head1 DESCRIPTION | ||||||||||
| 99 | |||||||||||
| 100 | WARNING: Codebase is alpha with extreme prejudice. Assume that bugs are | ||||||||||
| 101 | teeming and that the API is subject to change. | ||||||||||
| 102 | |||||||||||
| 103 | L<Template::Caribou> is a L<Moose>-based, class-centric templating system | ||||||||||
| 104 | mostly aimed at producing sgml-like outputs, mostly HTML, but also XML, SVG, etc. It is | ||||||||||
| 105 | heavily inspired by L<Template::Declare>. | ||||||||||
| 106 | |||||||||||
| 107 | For a manual on how to use C<Template::Caribou>, have a peek at | ||||||||||
| 108 | L<Template::Caribou::Manual>. | ||||||||||
| 109 | |||||||||||
| 110 | When C<use>d within a namespace, C<Template::Caribou> will apply the role L<Template::Caribou::Role> | ||||||||||
| 111 | to it (and auto-turn the namespace into Moose class if it wasn't a Moose class or role already), | ||||||||||
| 112 | as well as import the keywords C<template> and C<attr> (the latter from | ||||||||||
| 113 | L<Template::Caribou::Tags>), as well as load L<Template::Caribou::Utils>. | ||||||||||
| 114 | |||||||||||
| 115 | =head1 AUTHOR | ||||||||||
| 116 | |||||||||||
| 117 | Yanick Champoux <yanick@cpan.org> | ||||||||||
| 118 | |||||||||||
| 119 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 120 | |||||||||||
| 121 | This software is copyright (c) 2017 by Yanick Champoux. | ||||||||||
| 122 | |||||||||||
| 123 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 124 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||