| 1 | ###################################################### | ||||||||||||
| 2 | # UnknownBlock.pm | ||||||||||||
| 3 | ###################################################### | ||||||||||||
| 4 | # Author: Peter Yang, Thomas Hladish | ||||||||||||
| 5 | # $Id: UnknownBlock.pm,v 1.27 2007/09/24 04:52:14 rvos Exp $ | ||||||||||||
| 6 | |||||||||||||
| 7 | #################### START POD DOCUMENTATION ################## | ||||||||||||
| 8 | |||||||||||||
| 9 | =head1 NAME | ||||||||||||
| 10 | |||||||||||||
| 11 | Bio::NEXUS::UnknownBlock - Represents a simple object for storing information unrecognized blocks by the Bio::NEXUS module. | ||||||||||||
| 12 | |||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||
| 14 | |||||||||||||
| 15 | $block_object = new Bio::NEXUS::UnknownBlock($block_type, $block, $verbose); | ||||||||||||
| 16 | |||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||
| 18 | |||||||||||||
| 19 | Provides a simple way of storing information about a block that is not currently recognized by the NEXUS package. This is useful for remembering custom blocks. | ||||||||||||
| 20 | |||||||||||||
| 21 | =head1 FEEDBACK | ||||||||||||
| 22 | |||||||||||||
| 23 | All feedback (bugs, feature enhancements, etc.) are all greatly appreciated. There are no mailing lists at this time for the Bio::NEXUS::TaxaBlock module, so send all relevant contributions to Dr. Weigang Qiu (weigang@genectr.hunter.cuny.edu). | ||||||||||||
| 24 | |||||||||||||
| 25 | =head1 AUTHORS | ||||||||||||
| 26 | |||||||||||||
| 27 | Peter Yang (pyang@rice.edu) | ||||||||||||
| 28 | Thomas Hladish (tjhladish at yahoo) | ||||||||||||
| 29 | |||||||||||||
| 30 | =head1 VERSION | ||||||||||||
| 31 | |||||||||||||
| 32 | $Revision: 1.27 $ | ||||||||||||
| 33 | |||||||||||||
| 34 | =head1 METHODS | ||||||||||||
| 35 | |||||||||||||
| 36 | =cut | ||||||||||||
| 37 | |||||||||||||
| 38 | package Bio::NEXUS::UnknownBlock; | ||||||||||||
| 39 | |||||||||||||
| 40 | 35 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 41 | #use Carp; # XXX this is not used, might as well not import it! | ||||||||||||
| 42 | #use Data::Dumper; # XXX this is not used, might as well not import it! | ||||||||||||
| 43 | 35 | ▶ | use Bio::NEXUS::Functions; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | 35 | ▶ | use Bio::NEXUS::Block; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 35 | ▶ | use Bio::NEXUS::Util::Exceptions; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 46 | 35 | ▶ | use Bio::NEXUS::Util::Logger; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 47 | 35 | ▶ | use vars qw(@ISA $VERSION $AUTOLOAD); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 48 | 35 | ▶ | use Bio::NEXUS; $VERSION = $Bio::NEXUS::VERSION; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | 35 | @ISA = qw(Bio::NEXUS::Block); | |||||||||||
| 50 | |||||||||||||
| 51 | 35 | my $logger = Bio::NEXUS::Util::Logger->new(); | |||||||||||
| 52 | |||||||||||||
| 53 | =head2 new | ||||||||||||
| 54 | |||||||||||||
| 55 | Title : new | ||||||||||||
| 56 | Usage : block_object = new Bio::NEXUS::UnknownBlock($block_type, $commands, $verbose); | ||||||||||||
| 57 | Function: Creates a new Bio::NEXUS::UnknownBlock object and automatically reads the file | ||||||||||||
| 58 | Returns : Bio::NEXUS::UnknownBlock object | ||||||||||||
| 59 | Args : type (string), the commands/comments to parse (array ref), and a verbose flag (0 or 1; optional) | ||||||||||||
| 60 | |||||||||||||
| 61 | =cut | ||||||||||||
| 62 | |||||||||||||
| 63 | 8 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 64 | 8 | my ( $class, $type, $commands, $verbose ) = @_; | |||||||||||
| 65 | 0 | ▶ | unless ($type) { ( $type = lc $class ) =~ s/Bio::NEXUS::(.+)Block/$1/i; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | 8 | my $self = { type => $type, }; | |||||||||||
| 67 | 8 | bless $self, $class; | |||||||||||
| 68 | 8 | $self->_parse_block( $commands, $verbose ); | |||||||||||
| 69 | 8 | return $self; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | =begin comment | ||||||||||||
| 73 | |||||||||||||
| 74 | Title : _parse_block | ||||||||||||
| 75 | Usage : $block->_parse_block(\@commands, $verbose_flag); | ||||||||||||
| 76 | Function: Simple block parser that stores commands literally | ||||||||||||
| 77 | Returns : none | ||||||||||||
| 78 | Args : array ref of commands, as parsed by Bio::NEXUS::read; and an optional verbose flag | ||||||||||||
| 79 | |||||||||||||
| 80 | =end comment | ||||||||||||
| 81 | |||||||||||||
| 82 | =cut | ||||||||||||
| 83 | |||||||||||||
| 84 | 8 | ▶ | sub _parse_block { | ||||||||||
|
Subroutine
_parse_block: called CC=3 SCAR=11.0
| |||||||||||||
| 85 | 8 | my ( $self, $commands, $verbose ) = @_; | |||||||||||
| 86 | 8 | my $type = $self->get_type(); | |||||||||||
| 87 | 8 | $logger->info("Analyzing $type block now."); | |||||||||||
| 88 | |||||||||||||
| 89 | CMD: | ||||||||||||
| 90 | 8 | for my $command (@$commands) { | |||||||||||
| 91 | 26 | ▶ | next CMD if $command =~ /^\s*(?:begin|end)/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | 10 | push @{ $self->{'block'} }, $command; | |||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | 8 | $logger->info("Analysis of $type block complete."); | |||||||||||
| 96 | 8 | return; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | =begin comment | ||||||||||||
| 100 | |||||||||||||
| 101 | Name : _write | ||||||||||||
| 102 | Usage : $block->_write(); | ||||||||||||
| 103 | Function: Writes NEXUS block from stored data | ||||||||||||
| 104 | Returns : none | ||||||||||||
| 105 | Args : none | ||||||||||||
| 106 | |||||||||||||
| 107 | =end comment | ||||||||||||
| 108 | |||||||||||||
| 109 | =cut | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | sub _write { | ||||||||||
|
Subroutine
_write: not called CC=4 SCAR=30.0
| |||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||
| 113 | 0 | ▶ | my $fh = shift || \*STDOUT; | ||||||||||
|
Condition0%0/2
shift() || \*STDOUT
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 114 | 0 | print $fh "BEGIN ", uc $self->get_type(), ";\n"; | |||||||||||
| 115 | 0 | my $commands = $self->{'block'}; | |||||||||||
| 116 | 0 | for my $cmd (@$commands) { | |||||||||||
| 117 | 0 | ▶ | next if lc $cmd eq 'begin'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | 0 | print $fh "$cmd\n"; | |||||||||||
| 119 | } | ||||||||||||
| 120 | 0 | print $fh "END;\n"; | |||||||||||
| 121 | } | ||||||||||||
| 122 | |||||||||||||
| 123 | 8 | ▶ | sub AUTOLOAD { | ||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=21.1
| |||||||||||||
| 124 | 8 | ▶ | return if $AUTOLOAD =~ /DESTROY$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | 0 | my $package_name = __PACKAGE__ . '::'; | |||||||||||
| 126 | |||||||||||||
| 127 | # The following methods are deprecated and are temporarily supported | ||||||||||||
| 128 | # via a warning and a redirection | ||||||||||||
| 129 | 0 | my %synonym_for = ( | |||||||||||
| 130 | |||||||||||||
| 131 | # "${package_name}parse" => "${package_name}_parse_tree", # example | ||||||||||||
| 132 | ); | ||||||||||||
| 133 | |||||||||||||
| 134 | 0 | ▶ | if ( defined $synonym_for{$AUTOLOAD} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | 0 | $logger->warn( "$AUTOLOAD() is deprecated; use $synonym_for{$AUTOLOAD}() instead" ); | |||||||||||
| 136 | 0 | goto &{ $synonym_for{$AUTOLOAD} }; | |||||||||||
| 137 | } | ||||||||||||
| 138 | else { | ||||||||||||
| 139 | 0 | Bio::NEXUS::Util::Exceptions::UnknownMethod->throw( | |||||||||||
| 140 | 'error' => "ERROR: Unknown method $AUTOLOAD called" | ||||||||||||
| 141 | ); | ||||||||||||
| 142 | } | ||||||||||||
| 143 | } | ||||||||||||
| 144 | |||||||||||||
| 145 | 35 | 1; | |||||||||||