#!/usr/bin/perl -w
use strict;
use Tracing 'print';
TRACE("-------- Starting archiver ---------");
TRACEF("We are going to try to archive %d items", scalar @ARGV);
DUMP("List of things to archive", \@ARGV);
archive_em($_) foreach(@ARGV);
sub archive_em {
TRACE_HERE();
my $thing = shift;
unless ($thing =~ /^([\w.\-/]+)$/) {
warn "bad chars in: $thing";
return;
}
rename $thing, $thing.".archive" or warn "Couldn't archive $thing: $!";
TRACE("Tried to archive $thing");
}
####
package MyModule;
sub my_routine {
TRACE("hello");
}
sub my_other_routine {
TRACE_HERE();
}
#Stubs for Tracing
sub TRACE {}
sub TRACE_HERE {}
##
##
use MyModule;
use Tracing;
deep_import Tracing log => '/var/log/myapp.log';
MyModule::my_routine();
MyModule::my_other_routine();
##
##
package MyModule;
use Assertions 'die';
sub format_cols {
my ($data, $columns, $width) = @_;
ASSERT(defined ($columns) && $columns > 0, "columns is positive");
ASSERT(defined ($width) && $width > 0);
my $col_width = $width / $columns;
for (1 .. $columns) {
# ...
}
}
##
##
use Assertions 'test';
plan tests;
ASSERT(1 == 1, "an example test");
my %observed = parse_data("a1b4c6");
ASSERT(EQUAL(\%observed, {a => 1, b => 4, c => 6}), 'parse_data, parsed ok');
my $returned = munge_data(\%observed);
ASSERT(EQUALS_FILE($returned, 'expected.txt'), 'munge_data is good at munging');
ASSERT(DIED(sub { $object_to_test->method(@bad_inputs) }));