| 1 | package Pugs::Runtime::StrPos; | ||||||||||
| 2 | # Documentation in the __END__ | ||||||||||
| 3 | |||||||||||
| 4 | #use 5.006; ??? | ||||||||||
| 5 | 36 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 36 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 36 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 36 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 36 | ▶ | use overload ( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.2
| |||||||||||
| 11 | 'bool' => \&bool, | ||||||||||
| 12 | '0+' => \&graphs, | ||||||||||
| 13 | 0 | ▶ | '++' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 14 | 0 | $_[0]->{codes} = ($_[0]->add_graphs( 1 ))->{codes}; | |||||||||
| 15 | }, | ||||||||||
| 16 | 0 | ▶ | '+=' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 17 | 0 | $_[0]->{codes} += $_[1]; | |||||||||
| 18 | }, | ||||||||||
| 19 | 0 | ▶ | '+' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 0 | ($_[0]->add_graphs( $_[1] ))->{codes}; | |||||||||
| 21 | }, | ||||||||||
| 22 | 0 | ▶ | '=' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 23 | 0 | my $self = shift; | |||||||||
| 24 | 0 | bless {%$self}, ref $self; | |||||||||
| 25 | }, | ||||||||||
| 26 | 36 | fallback => 1, | |||||||||
| 27 | 36 | ); | |||||||||
| 28 | |||||||||||
| 29 | # new({ str => "...", codes => $n }); | ||||||||||
| 30 | # $str must be utf-8 | ||||||||||
| 31 | # $n can be undef, meaning "nowhere in this string" | ||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 33 | 0 | return bless $_[1], $_[0]; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | # codes is the default perl5 representation | ||||||||||
| 37 | # graphs is the default perl6 representation | ||||||||||
| 38 | 0 | ▶ | sub from_str_graphs { | ||||||||
|
Subroutine
from_str_graphs: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 39 | |||||||||||
| 40 | # -- downgrade as appropriate | ||||||||||
| 41 | #die "string has invalid internal encoding" | ||||||||||
| 42 | 0 | ▶ | return from_str_codes( @_ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | unless utf8::is_utf8( $_[1] ); | ||||||||||
| 44 | |||||||||||
| 45 | 0 | $_[1] =~ m/^\X{$_[2]}/g; | |||||||||
| 46 | 0 | return bless { str => $_[1], codes => pos($_[1]) }, $_[0]; | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | ▶ | sub from_str_codes { | ||||||||
|
Subroutine
from_str_codes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 50 | 0 | return bless { str => $_[1], codes => $_[2] }, $_[0]; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub from_str { | ||||||||
|
Subroutine
from_str: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 54 | 0 | return bless { str => $_[1], codes => pos( $_[1] ) }, $_[0]; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 0 | return bless { %{$_[0]} }, ref( $_[0] ); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | sub bool { | ||||||||
|
Subroutine
bool: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | defined $_[0]->{codes} | ||||||||||
| 63 | 0 | } | |||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub codes { | ||||||||
|
Subroutine
codes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 66 | $_[0]->{codes} | ||||||||||
| 67 | 0 | } | |||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub bytes { | ||||||||
|
Subroutine
bytes: not called CC=3 SCAR=19.2
Pod
undocumented
| |||||||||||
| 70 | 0 | ▶ | return undef unless defined $_[0]->{codes}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | |||||||||||
| 72 | # -- downgrade as appropriate | ||||||||||
| 73 | #die "string has invalid internal encoding" | ||||||||||
| 74 | return $_[0]->codes | ||||||||||
| 75 | 0 | ▶ | unless utf8::is_utf8( $_[0]->{str} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | |||||||||||
| 77 | 0 | my $s = substr( $_[0]->{str}, 0, $_[0]->{codes} ); | |||||||||
| 78 | { | ||||||||||
| 79 | 0 | ▶ | use bytes; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||
| 80 | 0 | return length( $s ); | |||||||||
| 81 | } | ||||||||||
| 82 | #my @bytes = unpack("C*", substr( $_[0]->{str}, 0, $_[0]->{codes} ) ); | ||||||||||
| 83 | #print "[",join(",", @bytes),"]\n"; | ||||||||||
| 84 | #return scalar @bytes; | ||||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub graphs { | ||||||||
|
Subroutine
graphs: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 88 | 0 | ▶ | return undef unless defined $_[0]->{codes}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | |||||||||||
| 90 | # -- downgrade as appropriate | ||||||||||
| 91 | #die "string has invalid internal encoding" | ||||||||||
| 92 | return $_[0]->codes | ||||||||||
| 93 | 0 | ▶ | unless utf8::is_utf8( $_[0]->{str} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | |||||||||||
| 95 | #return scalar( substr( $_[0]->{str}, 0, $_[0]->{codes} ) =~ m/\X/g ); | ||||||||||
| 96 | 0 | my @g = substr( $_[0]->{str}, 0, $_[0]->{codes} ) =~ m/\X/g; | |||||||||
| 97 | 0 | return scalar @g; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | sub langs { | ||||||||
|
Subroutine
langs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 101 | 0 | die "TODO: langs()"; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | sub add_codes { | ||||||||
|
Subroutine
add_codes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 105 | 0 | (ref $_[0])->from_str_codes( $_[0]->{str}, $_[0]->codes + $_[1] ); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub add_graphs { | ||||||||
|
Subroutine
add_graphs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 109 | 0 | (ref $_[0])->from_str_graphs( $_[0]->{str}, $_[0]->graphs + $_[1] ); | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | sub perl { | ||||||||
|
Subroutine
perl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 113 | 0 | local $Data::Dumper::Terse = 1; | |||||||||
| 114 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||
| 115 | 0 | local $Data::Dumper::Pad = ' '; | |||||||||
| 116 | 0 | return Dumper( $_[0] ); | |||||||||
| 117 | } | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub yaml { | ||||||||
|
Subroutine
yaml: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 120 | 0 | require YAML::Syck; | |||||||||
| 121 | # interoperability with other YAML/Syck bindings: | ||||||||||
| 122 | 0 | $YAML::Syck::ImplicitTyping = 1; | |||||||||
| 123 | 0 | YAML::Syck::Dump( $_[0] ); | |||||||||
| 124 | } | ||||||||||
| 125 | |||||||||||
| 126 | # for Pugs interoperability | ||||||||||
| 127 | 0 | ▶ | sub dump_hs { | ||||||||
|
Subroutine
dump_hs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 128 | 0 | die "TODO"; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 36 | 1; | |||||||||
| 132 | |||||||||||
| 133 | __END__ | ||||||||||