File Coverage

blib/lib/PPIx/Regexp/Structure/Main.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 8 75.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 38 40 95.0


line stmt bran cond sub pod time code
1             =head1 NAME
2              
3             PPIx::Regexp::Structure::Main - Represent a regular expression proper, or a substitution
4              
5             =head1 SYNOPSIS
6              
7             use PPIx::Regexp::Dumper;
8             PPIx::Regexp::Dumper->new( 'qr{foo}smx' )
9             ->print();
10              
11             =head1 INHERITANCE
12              
13             C<PPIx::Regexp::Structure::Main> is a
14             L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15              
16             C<PPIx::Regexp::Structure::Main> is the parent of
17             L<PPIx::Regexp::Structure::Regexp|PPIx::Regexp::Structure::Regexp> and
18             L<PPIx::Regexp::Structure::Replacement|PPIx::Regexp::Structure::Replacement>.
19              
20             =head1 DESCRIPTION
21              
22             This abstract class represents one of the top-level structures in the
23             expression. Both
24             L<PPIx::Regexp::Structure::Regexp|PPIx::Regexp::Structure::Regexp> and
25             L<PPIx::Regexp::Structure::Replacement|PPIx::Regexp::Structure::Replacement>
26             are derived from it.
27              
28             =head1 METHODS
29              
30             This class provides the following public methods. Methods not documented
31             here are private, and unsupported in the sense that the author reserves
32             the right to change or remove them without notice.
33              
34             =cut
35              
36             package PPIx::Regexp::Structure::Main;
37              
38 9     9   65 use strict;
  9         11  
  9         242  
39 9     9   31 use warnings;
  9         12  
  9         380  
40              
41 9     9   34 use base qw{ PPIx::Regexp::Structure };
  9         12  
  9         677  
42              
43 9     9   36 use PPIx::Regexp::Constant qw{ @CARP_NOT };
  9         26  
  9         2300  
44              
45             our $VERSION = '0.091';
46              
47             =head2 delimiters
48              
49             This method returns a string representing the delimiters of a regular
50             expression or substitution string. In the case of something like
51             C<s/foo/bar/>, it will return '//' for both the regular expression and
52             the replacement.
53              
54             =cut
55              
56             sub delimiters {
57 152     152 1 253 my ( $self ) = @_;
58 152         189 my @delims;
59 152         262 foreach my $method ( qw{ start finish } ) {
60 304         412 push @delims, undef;
61 304 100       845 defined ( my $obj = $self->$method() )
62             or next;
63 301 50       611 defined ( my $str = $obj->content() )
64             or next;
65 301         538 $delims[-1] = $str;
66             }
67 152 100       310 defined ( $delims[0] )
68             or $delims[0] = $delims[1];
69 152         513 return $delims[0] . $delims[1];
70             }
71              
72             =head2 interpolates
73              
74             This method returns true if the regular expression or replacement
75             interpolates, and false otherwise. All it really does is to check
76             whether the ending delimiter is a single quote.
77              
78             =cut
79              
80             sub interpolates {
81 3     3 1 8 my ( $self ) = @_;
82 3 50       18 my $finish = $self->finish( 0 ) or return 1;
83 3         11 return q<'> ne $finish->content();
84             }
85              
86             1;
87              
88             __END__
89              
90             =head1 SUPPORT
91              
92             Support is by the author. Please file bug reports at
93             L<https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
94             L<https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in
95             electronic mail to the author.
96              
97             =head1 AUTHOR
98              
99             Thomas R. Wyant, III F<wyant at cpan dot org>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             Copyright (C) 2009-2023, 2025 by Thomas R. Wyant, III
104              
105             This program is free software; you can redistribute it and/or modify it
106             under the same terms as Perl 5.10.0. For more details, see the full text
107             of the licenses in the directory LICENSES.
108              
109             This program is distributed in the hope that it will be useful, but
110             without any warranty; without even the implied warranty of
111             merchantability or fitness for a particular purpose.
112              
113             =cut
114              
115             # ex: set textwidth=72 :