Commits

Palmer, 2E0EOL  committed 17f42e0 Merge

Merge an example program which just reads at the moment, from the
experimental branch

  • Participants
  • Parent commits 7662090, 25c7e77
  • Branches f/201201-palmer-writer

Comments (0)

Files changed (1)

File t/example1.t

+#!/usr/bin/perl -w
+# Daybo Logic Checksum Reader Library for Perl
+# Copyright (c) 2012, David Duncan Ross Palmer, Daybo Logic
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+#     * Redistributions of source code must retain the above copyright notice,
+#       this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in the
+#       documentation and/or other materials provided with the distribution.
+#
+#     * Neither the name of the Daybo Logic nor the names of its contributors
+#       may be used to endorse or promote products derived from this software
+#       without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# This is an example showing how an example CHECKSUM.MD5 file could be read,
+# an entry eliminated, and the output written to a new file. The version of
+# the library is checked dynamically to avoid using features of older versions
+# of the library.  This serves as an example of real-world use of the library.
+# Pass -v to see progress.
+#
+#----------------------------------------------------------------------------
+package main;
+use strict;
+use warnings;
+use diagnostics;
+
+use Daybo::Checksum::Reader;
+use Getopt::Std;
+
+use constant TESTDATA_DIR   => 'testdata';
+use constant INPUT_CHECKSUM_FILE  => (TESTDATA_DIR() . '/' . 'CHECKSUM.MD5');
+
+use constant EXIT_SUCCESS => (0);
+use constant EXIT_FAILURE => (1);
+#----------------------------------------------------------------------------
+sub Main()
+{
+	my ( %opts, $readCount );
+	my $reader = Daybo::Checksum::Reader->new();
+
+	getopts('v', \%opts);
+	$readCount = $reader->Read(FileName => INPUT_CHECKSUM_FILE());
+	if ( $readCount ) {
+		printf("Read %d checksums from %s\n", $readCount, $reader->FileName())
+			if ( $opts{'v'} );
+
+		return EXIT_SUCCESS();
+	}
+	return EXIT_FAILURE();
+}
+#----------------------------------------------------------------------------
+exit(Main());
+#----------------------------------------------------------------------------