| 1 | package Padre::Plugin::Perl6::Util; | ||
| 2 | BEGIN { | ||
| 3 | $Padre::Plugin::Perl6::Util::VERSION = '0.71'; | ||
| 4 | } | ||
| 5 | |||
| 6 | # ABSTRACT: Perl 6 plugin utilities | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use Padre::Constant (); | ||
| 11 | |||
| 12 | # Get perl6 full executable path | ||
| 13 | sub perl6_exe { | ||
| 14 | my $exe = Padre::Constant::WIN32 ? 'perl6.exe' : 'perl6'; | ||
| 15 | |||
| 16 | # Look for the explicit environment variable | ||
| 17 | if ( $ENV{RAKUDO_DIR} ) { | ||
| 18 | my $perl6 = File::Spec->catfile( $ENV{RAKUDO_DIR}, $exe ); | ||
| 19 | if ( -f $perl6 and -x _ ) { | ||
| 20 | return $perl6; | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | # On Windows, look for the Six distribution | ||
| 25 | if (Padre::Constant::WIN32) { | ||
| 26 | |||
| 27 | # Find perl6.exe in PDX and later Six releases | ||
| 28 | my $perl6 = 'C:\\strawberry\\six\\bin\\perl6.exe'; | ||
| 29 | if ( -f $perl6 ) { | ||
| 30 | return $perl6; | ||
| 31 | } | ||
| 32 | |||
| 33 | # Stay compatible with almost-six 0.41 | ||
| 34 | $perl6 = 'C:\\strawberry\\six\\perl6.exe'; | ||
| 35 | if ( -f $perl6 ) { | ||
| 36 | return $perl6; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | # Look on the path | ||
| 41 | require File::Which; | ||
| 42 | my $perl6 = File::Which::which('perl6'); | ||
| 43 | if ( defined $perl6 and -f $perl6 and -x _ ) { | ||
| 44 | return $perl6; | ||
| 45 | } | ||
| 46 | |||
| 47 | return undef; | ||
| 48 | } | ||
| 49 | |||
| 50 | sub parrot_bin { | ||
| 51 | my $bin = shift; | ||
| 52 | my $exe = Padre::Constant::WIN32 ? "$bin.exe" : $bin; | ||
| 53 | |||
| 54 | # Look for the explicit RAKUDO_DIR | ||
| 55 | if ( $ENV{RAKUDO_DIR} ) { | ||
| 56 | my $command = File::Spec->catfile( $ENV{RAKUDO_DIR}, 'parrot_install', $exe ); | ||
| 57 | if ( -f $command and -x _ ) { | ||
| 58 | return $command; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | # On Windows, look for the Six distribution | ||
| 63 | if (Padre::Constant::WIN32) { | ||
| 64 | |||
| 65 | # Find parrot binary in PDX and later Six releases | ||
| 66 | my $command = "C:\\strawberry\\six\\bin\\$exe"; | ||
| 67 | if ( -f $command and -x _ ) { | ||
| 68 | return $command; | ||
| 69 | } | ||
| 70 | |||
| 71 | # Stay compatible with almost-six 0.41 | ||
| 72 | $command = "C:\\strawberry\\six\\parrot\\$exe"; | ||
| 73 | if ( -f $command and -x _ ) { | ||
| 74 | return $command; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | # Look in the path for the command, fwiw | ||
| 79 | require File::Which; | ||
| 80 | my $command = File::Which::which($bin); | ||
| 81 | if ( $command and -f $command and -x _ ) { | ||
| 82 | return $command; | ||
| 83 | } | ||
| 84 | |||
| 85 | return undef; | ||
| 86 | } | ||
| 87 | |||
| 88 | sub libparrot { | ||
| 89 | my $lib = Padre::Constant::WIN32 ? "libparrot.dll" : 'libparrot.so'; | ||
| 90 | |||
| 91 | # Look for the explicit RAKUDO_DIR | ||
| 92 | if ( $ENV{RAKUDO_DIR} ) { | ||
| 93 | my $libparrot = File::Spec->catfile( $ENV{RAKUDO_DIR}, 'parrot', $lib ); | ||
| 94 | if ( -f $libparrot ) { | ||
| 95 | return $libparrot; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | # On Windows, look for the Six distribution | ||
| 100 | if (Padre::Constant::WIN32) { | ||
| 101 | my $libparrot = "C:\\strawberry\\six\\parrot\\libparrot.dll"; | ||
| 102 | if ( -f $libparrot ) { | ||
| 103 | return $libparrot; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | return undef; | ||
| 108 | } | ||
| 109 | |||
| 110 | # | ||
| 111 | # Guess the new line for the current document | ||
| 112 | # can return \r, \r\n, or \n | ||
| 113 | # | ||
| 114 | sub guess_newline { | ||
| 115 | my $text = shift; | ||
| 116 | |||
| 117 | require Padre::Util; | ||
| 118 | my $doc_new_line_type = Padre::Util::newline_type($text); | ||
| 119 | my $new_line; | ||
| 120 | if ( $doc_new_line_type eq "WIN" ) { | ||
| 121 | $new_line = "\r\n"; | ||
| 122 | } elsif ( $doc_new_line_type eq "MAC" ) { | ||
| 123 | $new_line = "\r"; | ||
| 124 | } else { | ||
| 125 | |||
| 126 | #NONE, UNIX or MIXED | ||
| 127 | $new_line = "\n"; | ||
| 128 | } | ||
| 129 | |||
| 130 | return $new_line; | ||
| 131 | } | ||
| 132 | |||
| 133 | 1; | ||
| 134 | |||
| 135 | __END__ |