Shlomi Fish avatar Shlomi Fish committed 3bbaf8f

Add t/unit-calc-delay and extract a method.

Comments (0)

Files changed (4)

App-Countdown/Changes

 Revision history for App-Countdown
 
-        Add --version, --help, and --man flags.
+        * Add --version, --help, and --man flags.
             - Thanks to Steven Haryanto from
             http://blogs.perl.org/users/shlomi_fish/2012/11/three-command-line-utilities.html#comments
+        * Add t/unit-calc-delay.t
 
 0.0.4   Tue 13 Nov 19:10:14 IST 2012
         URL to the repo changed to fix a typo. Updated Build.PL.

App-Countdown/MANIFEST

 t/manifest.t
 t/pod-coverage.t
 t/pod.t
+t/unit-calc-delay.t
 Makefile.PL
 META.yml
 META.json

App-Countdown/lib/App/Countdown.pm

     return $self->{_delay};
 }
 
+sub _calc_delay {
+    my ($self, $delay_spec) = @_;
+
+    if ($delay_spec !~ /\A[1-9][0-9]*\z/)
+    {
+        Carp::confess ("Invalid delay. Must be a positive integer.");
+    }
+
+    return $delay_spec;
+}
+
 sub _init
 {
     my ($self, $args) = @_;
         Carp::confess ("You should pass a number of seconds.");
     }
 
-    if ($delay !~ /\A[1-9][0-9]*\z/)
-    {
-        Carp::confess ("Invalid delay. Must be a positive integer.");
-    }
+    $self->_delay(
+        $self->_calc_delay($delay)
+    );
 
     $self->_delay($delay);
 

App-Countdown/t/unit-calc-delay.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use App::Countdown;
+
+{
+    my $obj = App::Countdown->new({argv => [1]});
+
+    # TEST
+    is ($obj->_calc_delay('1'), 1, "_calc_delay(1) == 1");
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.