From d8abf58ba24b367d2a8cbd5c87c890a8498ec561 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 30 Jan 2007 18:21:17 +0000 Subject: [PATCH] added count git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@791 07558da8-63fa-0310-ba24-9fe276d99e06 --- lib/WebPAC/Normalize.pm | 17 +++++++++++++++-- t/3-normalize.t | 9 ++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/WebPAC/Normalize.pm b/lib/WebPAC/Normalize.pm index 2eedc07..69dac72 100644 --- a/lib/WebPAC/Normalize.pm +++ b/lib/WebPAC/Normalize.pm @@ -21,6 +21,7 @@ use Exporter 'import'; split_rec_on get set + count /; use warnings; @@ -41,11 +42,11 @@ WebPAC::Normalize - describe normalisaton rules using sets =head1 VERSION -Version 0.25 +Version 0.26 =cut -our $VERSION = '0.25'; +our $VERSION = '0.26'; =head1 SYNOPSIS @@ -1289,6 +1290,18 @@ sub get { return $v; } +=head2 count + + if ( count( @result ) == 1 ) { + # do something if only 1 result is there + } + +=cut + +sub count { + warn "## count ",dump(@_),$/; + return @_ . ''; +} # END 1; diff --git a/t/3-normalize.t b/t/3-normalize.t index 7a0826a..6dcc3b3 100755 --- a/t/3-normalize.t +++ b/t/3-normalize.t @@ -2,7 +2,7 @@ use strict; -use Test::More tests => 311; +use Test::More tests => 322; use Test::Exception; use Cwd qw/abs_path/; use blib; @@ -194,6 +194,13 @@ sub test_s { cmp_ok( join('', suffix('xy', 'cd') ), 'eq', 'cdxy', 'suffix'); cmp_ok( join('', surround('->', '<-', 'a','b','c') ), 'eq', '->a<-->b<-->c<-', 'surround'); + # count + my @el; + for my $i ( 0 .. 10 ) { + cmp_ok( count( @el ), '==', $i, "count($i)"); + push @el, "element $i"; + } + # lookups throws_ok { _set_load_row() } qr/CODE/, 'empty _set_load_row()'; -- 2.20.1