| 1 | package Test::CodeGen::Protection; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Test functions for generated files | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Test::Builder::Module; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use CodeGen::Protection qw(rewrite_code); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Module::Runtime qw(use_module); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | our @ISA = qw(Test::Builder::Module); | |||||||||
| 12 | 1 | our @EXPORT = qw( | |||||||||
| 13 | is_protected_document_ok | ||||||||||
| 14 | is_protected_file_ok | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 4 | ▶ | sub is_protected_document_ok ($$;$) { | ||||||||
|
Subroutine
is_protected_document_ok: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 4 | my ( $format, $code, $message ) = @_; | |||||||||
| 20 | 4 | my $tb = Test::CodeGen::Protection->builder; | |||||||||
| 21 | 4 | eval { | |||||||||
| 22 | 4 | rewrite_code( | |||||||||
| 23 | type => $format, | ||||||||||
| 24 | existing_code => $code, | ||||||||||
| 25 | protected_code => 'my $x = 1;', | ||||||||||
| 26 | ); | ||||||||||
| 27 | 1 | 1; | |||||||||
| 28 | }; | ||||||||||
| 29 | 4 | ▶ | if ( my $error = $@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 3 | $tb->ok( 0, $message ); | |||||||||
| 31 | 3 | $tb->diag($error); | |||||||||
| 32 | 3 | return; | |||||||||
| 33 | } | ||||||||||
| 34 | 1 | $tb->ok( 1, $message ); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 1 | ▶ | sub is_protected_file_ok ($$;$) { | ||||||||
|
Subroutine
is_protected_file_ok: called CC=3 SCAR=12.2
Pod
documented
| |||||||||||
| 39 | 1 | my ( $format, $file, $message ) = @_; | |||||||||
| 40 | 1 | my $tb = Test::CodeGen::Protection->builder; | |||||||||
| 41 | 1 | my $code; | |||||||||
| 42 | 1 | eval { | |||||||||
| 43 | 1 | ▶ | open my $fh, '<', $file or die "Cannot open '$file' for reading: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | $code = do { local $/; <$fh> }; | |||||||||
| 45 | }; | ||||||||||
| 46 | 1 | ▶ | if ( my $error = $@ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | $tb->ok( 0, $message ); | |||||||||
| 48 | 1 | $tb->diag($error); | |||||||||
| 49 | 1 | return; | |||||||||
| 50 | } | ||||||||||
| 51 | 0 | is_protected_document_ok $format, $code, $message; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 1 | 1; | |||||||||
| 55 | |||||||||||
| 56 | __END__ | ||||||||||