#!/usr/bin/perl use warnings; use strict; { package DupEventChecker; use IO::Dir; use Moose; use namespace::autoclean; has 'dir' => ( is => 'ro', isa => 'Str', required => 1 ); has '_dir' => ( is => 'ro', isa => 'IO::Dir', lazy => 1, builder => '_build_dir', handles => { read_dir => 'read' }, init_arg => undef, ); sub _build_dir { 'IO::Dir'->new(shift->dir) } __PACKAGE__->meta->make_immutable; } use FindBin; use Test::More tests => 3; use Test::Exception; dies_ok { 'DupEventChecker'->new } 'dir not provided'; my $checker = 'DupEventChecker'->new(dir => $FindBin::Bin); isa_ok $checker, 'DupEventChecker'; my $itself = grep $0 =~ m{(?:^|/)\Q$_\E$}x, $checker->read_dir; is $itself, 1, 'test script found';