Skip to content

Instantly share code, notes, and snippets.

@Woody2143
Created November 2, 2012 01:32
Show Gist options
  • Save Woody2143/3998086 to your computer and use it in GitHub Desktop.
Save Woody2143/3998086 to your computer and use it in GitHub Desktop.
I am a horrible horrible person
package Index;
use Moose;
use namespace::autoclean;
use Index::Types;
use IPC::System::Simple qw(capture);
use POSIX qw(strftime);
has 'date' => (
is => 'rw',
isa => 'Index::Types::Date',
default => sub {strftime '%Y%m%d', gmtime;},
coerce => 1,
);
has 'starttime' => (
is => 'rw',
isa => 'Index::Types::HourMinute',
default => '0000',
coerce => 1,
);
has 'endtime' => (
is => 'rw',
isa => 'Index::Types::HourMinute',
default => '2359',
coerce => 1,
);
has 'files' => (
is => 'ro',
isa => 'ArrayRef',
writer => '_set_files',
default => sub { [] },
);
has 'filteredfiles' => (
is => 'ro',
isa => 'ArrayRef',
writer => '_set_filtered_files',
default => sub { [] },
);
has 'cdrs' => (
is => 'ro',
isa => 'ArrayRef',
writer => '_set_cdrs',
default => sub { [] },
);
__PACKAGE__->meta->make_immutable();
try {
$calls = Index::TN->new( \%params );
if (defined $hour) {
$calls->convert_hour($hour) if defined $hour;
} else {
$calls->convert_range($range) if defined $range;
}
} catch {
$_ =~ m/__START__(.*)__END__/;
my $error;
if (defined $1) {
$error = $1;
} else {
$error = "SYSTEM ERROR! " . $_;
}
say STDERR "\n" . $error;
pod2usage(2);
};
package Index::Types;
use Moose::Util::TypeConstraints;
#-----------------------------------------------------------------------------
subtype 'Index::Types::Date'
=> as 'Str'
=> where { m/^[0-9]{8}$/ }
=> message { "__START__This date ($_) is not a valid date!__END__"};
coerce 'Index::Types::Date',
from 'Str',
via {
my $digits = $_;
$digits =~ s/[^0-9]//g; # Strip anything that isn't a digit.
return $digits;
};
#-----------------------------------------------------------------------------
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment