| 1 | package Bio::MUST::Core::Roles::Commentable; | ||||||||||||||||||||
| 2 | # ABSTRACT: Commentable Moose role for storable objects | ||||||||||||||||||||
| 3 | 18 | $Bio::MUST::Core::Roles::Commentable::VERSION = '0.252040'; | |||||||||||||||||||
| 4 | 18 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 18 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 18 | ▶ | use feature qw(say); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 18 | ▶ | use Bio::MUST::Core::Types; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 18 | ▶ | use Bio::MUST::Core::Constants qw(:files); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | has 'comments' => ( | ||||||||||||||||||||
| 14 | traits => ['Array'], | ||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||
| 16 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||
| 17 | 463 | ▶ | default => sub { [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 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 | 60 | ▶ | sub header { | ||||||||||||||||||
|
Subroutine
header: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 31 | 60 | my $self = shift; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 60 | ▶ | return "#\n" x 2 unless $self->count_comments; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 35 | ▶ | return '# ' . $self->get_comment(0) . "\n#\n" if $self->count_comments == 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 27 | return '# ' . $self->join_comments("\n# ") . "\n"; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 102237 | ▶ | sub is_comment { | ||||||||||||||||||
|
Subroutine
is_comment: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 40 | 102237 | my $self = shift; | |||||||||||||||||||
| 41 | 102237 | my $line = shift; | |||||||||||||||||||
| 42 | 102237 | ▶ | my $regex = shift // $COMMENT_LINE; | ||||||||||||||||||
|
Condition66%2/3
shift() // $Bio::MUST::Core::Roles::Commentable::COMMENT_LINE
MC/DC0%0/2
shift() // $Bio::MUST::Core::Roles::Commentable::COMMENT_LINE
shift()
$Bio::MUST::Core::Roles::Commentable::COMMENT_LINE
Truth table66%2/3
A // B
A= shift()B= $Bio::MUST::Core::Roles::Commentable::COMMENT_LINE
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # store comments from file header | ||||||||||||||||||||
| 45 | # TODO: prevent addition of further comments (after first data line) | ||||||||||||||||||||
| 46 | 102237 | my ($shebang, $comment) = $line =~ $regex; | |||||||||||||||||||
| 47 | 102237 | ▶ | if ($shebang) { # strip starting '#' and spaces | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 192 | ▶ | $self->add_comment($comment) if $comment; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 192 | return 1; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 102045 | return 0; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 18 | ▶ | no Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 18 | 1; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||