Fennec::Declare - Nice syntax for Fennec via Devel::Declare
Fennec is useful, but its syntax is not as nice as it could be. Leaving Devel::Declare out of core is a feature, but that does nto mean it shouldn't exist at all. This module provides Devel::Declare syntax enhancements to Fennec.
Devel::Declare is better than a source filter, but still magic in all kinds of possible bad ways. It adds new parsing capabilities to perl, but using it often still requires code to parse perl. Only perl can parse perl, as such there are likely many edge cases that have not been accounted for.
Shorter syntax, no more '=> sub', and semicolon is no longer required at the end of the code block. Optinally can still provide proto hash items like skip and todo. Also automatically shifts $self off. No need for my $self = shift.
# Original subname item_name => ( method => sub { my $self = shift; ... }, %proto ); # Sugar-coated subname item_name (%proto) { ... } # or subname item_name { ... }
my $self = shift; is always inserted into the beginning of the codeblock. This even happens on items that are not run as methods such as case {}. Since Fennec NEVER sends arguments to workflow/tester blocks this is harmless, $self will just be undefined in such cases.
package My::Test use strict; use warnings; use Fennec; use Fennec::Declare; tests simple { ok( $self, "Magically got self" ); $self->isa_ok( 'My::Test' ); $self->isa_ok( 'Fennec::TestFile' ); ok( 1, "In declared tests!" ); } tests 'complicated name' { ok( 1, "Complicated name!" ); } tests old => sub { ok( 1, "old style still works" ); }; tests old_deep => ( method => sub { ok( 1, "old with depth" )}, ); # Currently this does not work because of Fennec bug #58 # http://github.com/exodist/Fennec/issues#issue/58 # The syntax enhancement does as it should. tests add_specs ( todo => 'not really todo' ) { ok( 0, "This should be todo" ); } cases some_cases { ok( $self, "Magically got self" ); $self->isa_ok( 'My::Test' ); $self->isa_ok( 'Fennec::TestFile' ); my $x = 0; case case_a { $x = 10 } case case_b { $x = 100 } case case_c { # Cases are not methods, but $self is still provided. ok( !$self, "Cases are not methods" ); $x = 1000 } tests divisible_by_ten { ok( !($x % 10), "$x/10" )} tests positive { ok( $x, $x )} } describe a_describe { ok( $self, "Magically got self" ); $self->isa_ok( 'My::Test' ); $self->isa_ok( 'Fennec::TestFile' ); my $x; # Note, SPEC before/after blocks are not enhanced before_each { $x = 10 }; after_each { $x = 0 }; it is_ten { is( $x, 10, "x is 10" ); $x = 100 } it is_not_100 { isnt( $x, 100, "x is not 100" ); $x = 100 } } 1;
Using Fennec::Declare automatically provides enhancements to the following:
use Fennec::Declare @names_of_subs_to_enahnce;
So long as a sub takes for the form of:
subname item_name => ( method => sub { ... });
Fennec::Declare can enhance it. Simply provide the subs name to the use statement. before_XXX and after_XXX do not take this form, and thusly have not been enhanced.
Chad Granum exodist7@gmail.com
Copyright (C) 2010 Chad Granum
Fennec-Declare is free software; Standard perl licence.
Fennec-Declare is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
To install Fennec::Declare, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Fennec::Declare
CPAN shell
perl -MCPAN -e shell install Fennec::Declare
For more information on module installation, please visit the detailed CPAN module installation guide.