File Coverage

blib/lib/Bio/MUST/Core/Roles/Commentable.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 8 100.0
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 2 100.0
total 50 51 98.0


line stmt bran cond sub pod time code
1             package Bio::MUST::Core::Roles::Commentable;
2             # ABSTRACT: Commentable Moose role for storable objects
3             $Bio::MUST::Core::Roles::Commentable::VERSION = '0.212670';
4 17     17   11692 use Moose::Role;
  17         47  
  17         189  
5              
6 17     17   95863 use autodie;
  17         48  
  17         189  
7 17     17   94693 use feature qw(say);
  17         40  
  17         1674  
8              
9 17     17   147 use Bio::MUST::Core::Types;
  17         56  
  17         626  
10 17     17   114 use Bio::MUST::Core::Constants qw(:files);
  17         41  
  17         8546  
11              
12              
13             has 'comments' => (
14             traits => ['Array'],
15             is => 'ro',
16             isa => 'ArrayRef[Str]',
17             default => sub { [] },
18             handles => {
19             count_comments => 'count',
20             all_comments => 'elements',
21             join_comments => 'join',
22             add_comment => 'push',
23             get_comment => 'get',
24             insert_comment => 'unshift',
25             },
26             );
27              
28              
29              
30             sub header {
31 58     58 1 198 my $self = shift;
32              
33 58 100       2484 return "#\n" x 2 unless $self->count_comments;
34 35 100       1382 return '# ' . $self->get_comment(0) . "\n#\n" if $self->count_comments == 1;
35 27         1067 return '# ' . $self->join_comments("\n# ") . "\n";
36             }
37              
38              
39             sub is_comment {
40 102205     102205 1 181368 my $self = shift;
41 102205         160987 my $line = shift;
42 102205   66     257842 my $regex = shift // $COMMENT_LINE;
43              
44             # store comments from file header
45             # TODO: prevent addition of further comments (after first data line)
46 102205         302189 my ($shebang, $comment) = $line =~ $regex;
47 102205 100       211050 if ($shebang) { # strip starting '#' and spaces
48 190 100       3230 $self->add_comment($comment) if $comment;
49 190         1246 return 1;
50             }
51 102015         315777 return 0;
52             }
53              
54 17     17   142 no Moose::Role;
  17         47  
  17         113  
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =head1 NAME
62              
63             Bio::MUST::Core::Roles::Commentable - Commentable Moose role for storable objects
64              
65             =head1 VERSION
66              
67             version 0.212670
68              
69             =head1 SYNOPSIS
70              
71             # TODO
72              
73             =head1 DESCRIPTION
74              
75             # TODO
76              
77             =head1 METHODS
78              
79             =head2 header
80              
81             =head2 is_comment
82              
83             =head1 AUTHOR
84              
85             Denis BAURAIN <denis.baurain@uliege.be>
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             This software is copyright (c) 2013 by University of Liege / Unit of Eukaryotic Phylogenomics / Denis BAURAIN.
90              
91             This is free software; you can redistribute it and/or modify it under
92             the same terms as the Perl 5 programming language system itself.
93              
94             =cut