40 likes | 163 Vues
2008-06-18 davidrw. Devel::Cover::TT. David Westbrook (davidrw) dwestbrook@gmail.com. Combining Devel::Cover and Template-Toolkit for coverage stats on templates. Evaluate direct unit tests of templates!. 2008-06-18 davidrw. Initial Coverage Example. { title => 'Test1',
E N D
2008-06-18 davidrw Devel::Cover::TT David Westbrook (davidrw) dwestbrook@gmail.com Combining Devel::Cover and Template-Toolkitfor coverage stats on templates. Evaluate direct unit tests of templates!
2008-06-18 davidrw Initial Coverage Example { title => 'Test1', verbose => 0, rows => [ { x => 1, y => 2, }, { x => 2, y => 4, }, ], }; [% title %][% ' - ' _ subtitle IF subtitle %] ~~~~ [% PROCESS show_rows IF verbose && rows.size > 0 %] ~~~~ [% BLOCK show_rows %] [% FOREACH row = rows -%] [% row.x %] / [% row.y %] = [% row.y == 0 ? 'N/A' : ( row.x / row.y ) %] [% END -%] [% END %]
2008-06-18 davidrw Concepts & Methodology • Key Concepts • Coverage of TT templates • Unit tests on TT templates • Issues • Coverage of .ttc, not tmpl itself • Uncoverable TT-generated code • TODO • Gather Feedback! • Review & test TT hooks, overloads, subclassing • Ensure robustness over hacks Interface use Devel::Cover::TT qw{ -silent 1 -ignore . }; # Devel::Cover::TT::* Provider, Document Approach BEFORE Cache file contents: Template::Document->new( .... ); To read from cache: $foo = require $cachefile AFTER Cache file contents: package path::to:tmpl::example_tmpl.pm; sub getDocument { Template::Document->new( .... ); } 1; To read from cache: eval { use path::to:tmpl::example_tmpl; $foo = path::to:tmpl::example_tmpl->getDocument(); }
2008-06-18 davidrw Analysis & Improved Coverage! { title => 'Test2', subtitle => 'second test', verbose => 1, rows => [ { x => 1, y => 2, }, { x => 3, y => 0, }, { x => 2, y => 4, }, ], }; && rows.size > 0