Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / PPI / Token / Quote / Single.pm
1 package PPI::Token::Quote::Single;
2
3 =pod
4
5 =head1 NAME
6
7 PPI::Token::Quote::Single - A 'single quote' token
8
9 =head1 INHERITANCE
10
11   PPI::Token::Quote::Single
12   isa PPI::Token::Quote
13       isa PPI::Token
14           isa PPI::Element
15
16 =head1 SYNOPSIS
17
18   'This is a single quote'
19   
20   q{This is a literal, but NOT a single quote}
21
22 =head1 DESCRIPTION
23
24 A C<PPI::Token::Quote::Single> object represents a single quoted string
25 literal. 
26
27 =head1 METHODS
28
29 There are no methods available for C<PPI::Token::Quote::Single> beyond
30 those provided by the parent L<PPI::Token::Quote>, L<PPI::Token> and
31 L<PPI::Element> classes.
32
33 Got any ideas for methods? Submit a report to rt.cpan.org!
34
35 =cut
36
37 use strict;
38 use PPI::Token::Quote ();
39 use PPI::Token::_QuoteEngine::Simple ();
40
41 use vars qw{$VERSION @ISA};
42 BEGIN {
43         $VERSION = '1.206';
44         @ISA     = qw{
45                 PPI::Token::_QuoteEngine::Simple
46                 PPI::Token::Quote
47         };
48 }
49
50
51
52
53
54 #####################################################################
55 # PPI::Token::Quote Methods
56
57 =pod
58
59 =begin testing string 3
60
61 my $Document = PPI::Document->new( \"print 'foo';" );
62 isa_ok( $Document, 'PPI::Document' );
63 my $Single = $Document->find_first('Token::Quote::Single');
64 isa_ok( $Single, 'PPI::Token::Quote::Single' );
65 is( $Single->string, 'foo', '->string returns as expected' );
66
67 =end testing
68
69 =cut
70
71 sub string {
72         my $str = $_[0]->{content};
73         substr( $str, 1, length($str) - 2 );
74 }
75
76 =pod
77
78 =begin testing literal 21
79
80 my @pairs = (
81         "''",          '',
82         "'f'",         'f',
83         "'f\\'b'",     "f\'b",
84         "'f\\nb'",     "f\\nb",
85         "'f\\\\b'",    "f\\b",
86         "'f\\\\\\b'", "f\\\\b",
87         "'f\\\\\\\''", "f\\'",
88 );
89 while ( @pairs ) {
90         my $from  = shift @pairs;
91         my $to    = shift @pairs;
92         my $doc   = PPI::Document->new( \"print $from;" );
93         isa_ok( $doc, 'PPI::Document' );
94         my $quote = $doc->find_first('Token::Quote::Single');
95         isa_ok( $quote, 'PPI::Token::Quote::Single' );
96         is( $quote->literal, $to, "The source $from becomes $to ok" );
97 }
98
99 =end testing 
100
101 =cut
102
103 my %UNESCAPE = (
104         "\\'"  => "'",
105         "\\\\" => "\\",
106 );
107
108 sub literal {
109         # Unescape \\ and \' ONLY
110         my $str = $_[0]->string;
111         $str =~ s/(\\.)/$UNESCAPE{$1} || $1/ge;
112         return $str;
113 }
114
115 1;
116
117 =pod
118
119 =head1 SUPPORT
120
121 See the L<support section|PPI/SUPPORT> in the main module.
122
123 =head1 AUTHOR
124
125 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
126
127 =head1 COPYRIGHT
128
129 Copyright 2001 - 2009 Adam Kennedy.
130
131 This program is free software; you can redistribute
132 it and/or modify it under the same terms as Perl itself.
133
134 The full text of the license can be found in the
135 LICENSE file included with this module.
136
137 =cut