File Coverage

blib/lib/Bio/NEXUS/UnknownBlock.pm
Criterion Covered Total %
statement 36 53 67.9
branch 3 10 30.0
condition 0 2 0.0
subroutine 9 11 81.8
pod 1 1 100.0
total 49 77 63.6


line stmt bran cond sub pod time code
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 34     34   207 use strict;
  34         71  
  34         1375  
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 34     34   199 use Bio::NEXUS::Functions;
  34         83  
  34         8957  
44 34     34   298 use Bio::NEXUS::Block;
  34         79  
  34         964  
45 34     34   195 use Bio::NEXUS::Util::Exceptions;
  34         78  
  34         1398  
46 34     34   224 use Bio::NEXUS::Util::Logger;
  34         70  
  34         1215  
47 34     34   199 use vars qw(@ISA $VERSION $AUTOLOAD);
  34         76  
  34         2667  
48 34     34   197 use Bio::NEXUS; $VERSION = $Bio::NEXUS::VERSION;
  34         91  
  34         23958  
49             @ISA = qw(Bio::NEXUS::Block);
50              
51             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             sub new {
64 8     8 1 18 my ( $class, $type, $commands, $verbose ) = @_;
65 8 50       23 unless ($type) { ( $type = lc $class ) =~ s/Bio::NEXUS::(.+)Block/$1/i; }
  0         0  
66 8         27 my $self = { type => $type, };
67 8         23 bless $self, $class;
68 8         24 $self->_parse_block( $commands, $verbose );
69 8         24 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             sub _parse_block {
85 8     8   11 my ( $self, $commands, $verbose ) = @_;
86 8         37 my $type = $self->get_type();
87 8         48 $logger->info("Analyzing $type block now.");
88              
89             CMD:
90 8         22 for my $command (@$commands) {
91 26 100       170 next CMD if $command =~ /^\s*(?:begin|end)/i;
92 10         19 push @{ $self->{'block'} }, $command;
  10         30  
93             }
94              
95 8         45 $logger->info("Analysis of $type block complete.");
96 8         15 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             sub _write {
112 0     0     my $self = shift;
113 0   0       my $fh = shift || \*STDOUT;
114 0           print $fh "BEGIN ", uc $self->get_type(), ";\n";
115 0           my $commands = $self->{'block'};
116 0           for my $cmd (@$commands) {
117 0 0         next if lc $cmd eq 'begin';
118 0           print $fh "$cmd\n";
119             }
120 0           print $fh "END;\n";
121             }
122              
123             sub AUTOLOAD {
124 0 0   0     return if $AUTOLOAD =~ /DESTROY$/;
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 0         if ( defined $synonym_for{$AUTOLOAD} ) {
135 0           $logger->warn( "$AUTOLOAD() is deprecated; use $synonym_for{$AUTOLOAD}() instead" );
136 0           goto &{ $synonym_for{$AUTOLOAD} };
  0            
137             }
138             else {
139 0           Bio::NEXUS::Util::Exceptions::UnknownMethod->throw(
140             'error' => "ERROR: Unknown method $AUTOLOAD called"
141             );
142             }
143             }
144              
145             1;