| 1 | # Copyright 2001-2026, Paul Johnson (paul@pjcj.net) | ||
| 2 | |||
| 3 | # This software is free. It is licensed under the same terms as Perl itself. | ||
| 4 | |||
| 5 | # The latest version of this software should be available from my homepage: | ||
| 6 | # https://pjcj.net | ||
| 7 | |||
| 8 | package Devel::Cover::Op; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | our $VERSION = '1.52'; # VERSION | ||
| 14 | |||
| 15 | use Devel::Cover::Dumper; | ||
| 16 | |||
| 17 | use Devel::Cover qw( -ignore blib -ignore \\wB\\w ); | ||
| 18 | use B::Concise qw( set_style add_callback ); | ||
| 19 | |||
| 20 | my %Style = ( | ||
| 21 | "terse" => [ | ||
| 22 | "(?(#label =>\n)?)(*( )*)#class (#addr) #name <#cover> (?([#targ])?) " | ||
| 23 | . "#svclass~(?((#svaddr))?)~#svval~(?(label \"#coplabel\")?)\n", | ||
| 24 | "(*( )*)goto #class (#addr)\n", | ||
| 25 | "#class pp_#name", | ||
| 26 | ], | ||
| 27 | "concise" => [ | ||
| 28 | "#hyphseq2 #addr10 #cover12 (*( (x( ;)x))*)<#classsym> " | ||
| 29 | . "#exname#arg(?([#targarglife])?)~#flags(?(/#private)?)(x(;~->#next)x)\n", | ||
| 30 | " (*( )*) goto #seq\n", | ||
| 31 | "(?(<#seq>)?)#exname#arg(?([#targarglife])?)", | ||
| 32 | ], | ||
| 33 | "debug" => [ | ||
| 34 | "#class (#addr)\n\tcover\t\t#cover\n\top_next\t\t#nextaddr\n\top_sibling\t#sibaddr\n\t" | ||
| 35 | . "op_ppaddr\tPL_ppaddr[OP_#NAME]\n\top_type\t\t#typenum\n\top_seq\t\t" | ||
| 36 | . "#seqnum\n\top_flags\t#flagval\n\top_private\t#privval\n" | ||
| 37 | . "(?(\top_first\t#firstaddr\n)?)(?(\top_last\t\t#lastaddr\n)?)" | ||
| 38 | . "(?(\top_sv\t\t#svaddr\n)?)", | ||
| 39 | " GOTO #addr\n", | ||
| 40 | "#addr", | ||
| 41 | ], | ||
| 42 | ); | ||
| 43 | |||
| 44 | my @Options; | ||
| 45 | |||
| 46 | sub import { | ||
| 47 | my ($class, @args) = @_; | ||
| 48 | set_style(@{ $Style{concise} }); | ||
| 49 | for (@args) { | ||
| 50 | /-(.*)/ && exists $Style{$1} ? set_style(@{ $Style{$1} }) : push @Options, | ||
| 51 | $_; | ||
| 52 | } | ||
| 53 | |||
| 54 | my $final = 1; | ||
| 55 | add_callback(sub { | ||
| 56 | my ($h, $op, $format, $level) = @_; | ||
| 57 | my $key = Devel::Cover::get_key($op); | ||
| 58 | # print Dumper Devel::Cover::coverage unless $d++; | ||
| 59 | if ($h->{seq}) { | ||
| 60 | my ($s, $b, $c) | ||
| 61 | = map Devel::Cover::coverage($final ? $final-- : 0)->{$_}{$key}, | ||
| 62 | qw(statement branch condition); | ||
| 63 | local $" = ","; | ||
| 64 | no warnings "uninitialized"; | ||
| 65 | $h->{cover} = $s ? "s[$s]" : $b ? "b[@$b]" : $c ? "c[@$c]" : ""; | ||
| 66 | } else { | ||
| 67 | $h->{cover} = ""; | ||
| 68 | } | ||
| 69 | }); | ||
| 70 | } | ||
| 71 | |||
| 72 | END { B::Concise::compile(@Options)->() } | ||
| 73 | |||
| 74 | 1 | ||
| 75 | |||
| 76 | __END__ |