Bio-RNA-Barriers

 view release on metacpan or  search on metacpan

lib/Bio/RNA/Barriers/Results.pm  view on Meta::CPAN

package Bio::RNA::Barriers::Results;
our $VERSION = '0.03';

use 5.012;
use strict;
use warnings;

use Moose;
use MooseX::StrictConstructor;
use namespace::autoclean;

use autodie qw(:all);
use Scalar::Util qw( reftype );
use File::Spec::Functions qw(catpath splitpath);

has [qw( seq file_name )] => (
    is       => 'ro',
    required => 1,
);

has _mins => (
    is       => 'ro',
    required => 1,
    init_arg => 'mins'
);

has $_ => (
    is => 'ro',
    predicate => "has_$_",
) foreach qw(_volume _directory);


use overload q{""} => 'stringify';

# Allow various calling styles of the constructor:
# new(barriers_handle): pass only file handle to read data from, file_name
#       will be undef.
# new(barriers_handle, barriers_file_path): read data from handle and set
#       file name from a given path
# new( barriers_file_path): open handle and read data from the passed
#       path, set file name accordingly
# new(hash_ref): manual construction from required attributes
around BUILDARGS => sub {
    my $orig  = shift;
    my $class = shift;

    return $class->$orig(@_) if @_ == 0 or @_ > 2;  # no special handling

    # Read Barriers file from handle and set constructor arguments.
    my $barriers_fh;
    my @args;
    if (@_ == 1 and not reftype $_[0]) {            # file path given
        my $file_path = shift;
        my ($volume, $directory, $file_name) = splitpath $file_path;
        push @args, (
            _volume    => $volume,
            _directory => $directory,
            file_name  => $file_name,
        );

        open $barriers_fh, '<', $file_path;
    }
    elsif (reftype $_[0] eq reftype \*STDIN) {      # file handle given
        if (@_ == 2) {
            # Check if second arg may be a file name
            return $class->$orig(@_) if reftype $_[1];  # it's no file name
            push @args, (file_name => $_[1]);
        }
        else {
            push @args, (file_name => undef);       # no file name given



( run in 0.958 second using v1.01-cache-2.11-cpan-13bb782fe5a )