line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::PlayCode::Plugin::DoubleToSingle; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24430
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
6
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:FAYLAND'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
around 'do_with_token' => sub { |
9
|
|
|
|
|
|
|
my $orig = shift; |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
my ( $token ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
if ( $token->isa('PPI::Token::Quote::Double') ) { |
14
|
|
|
|
|
|
|
# XXX? |
15
|
|
|
|
|
|
|
# why treat |
16
|
|
|
|
|
|
|
# bless( { |
17
|
|
|
|
|
|
|
# 'separator' => '"', |
18
|
|
|
|
|
|
|
# 'content' => '"c\\n"' |
19
|
|
|
|
|
|
|
# }, 'PPI::Token::Quote::Double' ); |
20
|
|
|
|
|
|
|
# "c\\n" as not interpolations |
21
|
|
|
|
|
|
|
# bug? |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# why "\012" is not interpolations?? |
24
|
|
|
|
|
|
|
# another bug? |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# skip all '\' because I don't know which is fine |
27
|
|
|
|
|
|
|
if ( not $token->interpolations and |
28
|
|
|
|
|
|
|
not $token->content =~ /\\/ ) { |
29
|
|
|
|
|
|
|
my $str = $token->string; |
30
|
|
|
|
|
|
|
if ( $str !~ /\'/) { |
31
|
|
|
|
|
|
|
return "'$str'"; |
32
|
|
|
|
|
|
|
} else { |
33
|
|
|
|
|
|
|
if ( $str !~ /\~/ ) { |
34
|
|
|
|
|
|
|
return 'q~' . $str . '~'; |
35
|
|
|
|
|
|
|
} else { |
36
|
|
|
|
|
|
|
return $token->content; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} elsif ( $token->isa('PPI::Token::Quote::Interpolate') ) { |
41
|
|
|
|
|
|
|
# PPI::Token::Quote::Interpolate no ->interpolations |
42
|
|
|
|
|
|
|
my $str = $token->string; |
43
|
|
|
|
|
|
|
if ( $str =~ /^\w+$/ ) { |
44
|
|
|
|
|
|
|
return "'$str'"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$orig->($self, @_); |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
no Moose::Role; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Acme::PlayCode::Plugin::DoubleToSingle - Play code with Single and Double |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Acme::PlayCode; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $app = new Acme::PlayCode; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$app->load_plugin('DoubleToSingle'); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $played_code = $app->play( $code ); |
69
|
|
|
|
|
|
|
# or |
70
|
|
|
|
|
|
|
my $played_code = $app->play( $filename ); |
71
|
|
|
|
|
|
|
# or |
72
|
|
|
|
|
|
|
$app->play( $filename, { rewrite_file => 1 } ); # override $filename with played code |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $a = "a"; |
77
|
|
|
|
|
|
|
my $b = "'b'"; |
78
|
|
|
|
|
|
|
my $c = qq~c~; |
79
|
|
|
|
|
|
|
my $d = qq~'d'~; |
80
|
|
|
|
|
|
|
my $e = q{e}; |
81
|
|
|
|
|
|
|
my $f = 'f'; |
82
|
|
|
|
|
|
|
if ( $a eq "a" ) { |
83
|
|
|
|
|
|
|
print "ok"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
becomes |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $a = 'a'; |
89
|
|
|
|
|
|
|
my $b = q~'b'~; |
90
|
|
|
|
|
|
|
my $c = 'c'; |
91
|
|
|
|
|
|
|
my $d = qq~'d'~; |
92
|
|
|
|
|
|
|
my $e = q{e}; |
93
|
|
|
|
|
|
|
my $f = 'f'; |
94
|
|
|
|
|
|
|
if ( $a eq 'a' ) { |
95
|
|
|
|
|
|
|
print 'ok'; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L<Acme::PlayCode>, L<Moose>, L<PPI>, L<MooseX::Object::Pluggable> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Fayland Lam, C<< <fayland at gmail.com> >> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Copyright 2008 Fayland Lam, all rights reserved. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
111
|
|
|
|
|
|
|
under the same terms as Perl itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |