| 1 | package Thrift::IDL::Comment; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Thrift::IDL::Comment | ||||||||||
| 6 | |||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||
| 8 | |||||||||||
| 9 | Inherits from L<Thrift::IDL::Base> | ||||||||||
| 10 | |||||||||||
| 11 | =cut | ||||||||||
| 12 | |||||||||||
| 13 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 4 | ▶ | use base qw(Thrift::IDL::Base); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 4 | __PACKAGE__->mk_accessors(qw(value)); | |||||||||
| 17 | |||||||||||
| 18 | =head1 METHODS | ||||||||||
| 19 | |||||||||||
| 20 | =head2 value | ||||||||||
| 21 | |||||||||||
| 22 | Scalar accessor | ||||||||||
| 23 | |||||||||||
| 24 | =cut | ||||||||||
| 25 | |||||||||||
| 26 | 4 | my %styles = ( | |||||||||
| 27 | c_multiline => qr{^/\* (.+?) \*/$}sx, | ||||||||||
| 28 | c_single => qr{^\/\/+ (.*?)$}x, | ||||||||||
| 29 | perl_single => qr{^[#]+ (.*?)$}x, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | =head2 style | ||||||||||
| 33 | |||||||||||
| 34 | Returns 'c_multiline', 'c_single' or 'perl_single' depending on what form the comment takes | ||||||||||
| 35 | |||||||||||
| 36 | =cut | ||||||||||
| 37 | |||||||||||
| 38 | 1 | ▶ | sub style { | ||||||||
|
Subroutine
style: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 39 | 1 | my ($self) = @_; | |||||||||
| 40 | |||||||||||
| 41 | 1 | my $value = $self->value; | |||||||||
| 42 | 1 | keys %styles; # reset the each | |||||||||
| 43 | 1 | ▶ | while (my ($style, $regex) = each %styles) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 2 | my ($escaped_value) = $value =~ $regex; | |||||||||
| 45 | 2 | ▶ | next unless defined $escaped_value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 1 | return $style; | |||||||||
| 47 | } | ||||||||||
| 48 | 0 | die "Unrecognized comment style for '$value'"; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | =head2 escaped_value | ||||||||||
| 52 | |||||||||||
| 53 | Returns the content of the comment, based on the C<style> | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub escaped_value { | ||||||||
|
Subroutine
escaped_value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 58 | 1 | my ($self) = @_; | |||||||||
| 59 | 1 | my $value = $self->escaped_value_with_whitespace; | |||||||||
| 60 | 1 | $value =~ s/^\s+//; | |||||||||
| 61 | 1 | $value =~ s/\s+$//; | |||||||||
| 62 | 1 | return $value; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 1 | ▶ | sub escaped_value_with_whitespace { | ||||||||
|
Subroutine
escaped_value_with_whitespace: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 66 | 1 | my ($self) = @_; | |||||||||
| 67 | |||||||||||
| 68 | 1 | my ($escaped_value) = $self->value =~ $styles{$self->style}; | |||||||||
| 69 | 1 | return $escaped_value; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 4 | 1; | |||||||||