1. Shlomi Fish
  2. perl-App-Countdown

Commits

Shlomi Fish  committed 3bbaf8f

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

  • Participants
  • Parent commits 91ce4cc
  • Branches default

Comments (0)

Files changed (4)

File App-Countdown/Changes

View file
 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.

File App-Countdown/MANIFEST

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

File App-Countdown/lib/App/Countdown.pm

View file
     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);
 

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

View file
+#!/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");
+}
+