Created
November 2, 2012 01:32
-
-
Save Woody2143/3998086 to your computer and use it in GitHub Desktop.
I am a horrible horrible person
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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