| 1 | package App::SimpleScan::Plugin::Snapshot; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 20 | our $VERSION = '1.03'; | |||||||||||||
| 4 | |||||||||||||||
| 5 | 20 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 20 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 20 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 20 | ▶ | use File::Path; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 20 | my($snapdir, $snapshot, $snap_prefix, $snap_layout); | |||||||||||||
| 11 | |||||||||||||||
| 12 | 19 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 20 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 19 | *{caller() . '::snapshot'} = \&snapshot; | |||||||||||||
| 15 | 19 | *{caller() . '::snapshots_to'} = \&snapshots_to; | |||||||||||||
| 16 | 19 | *{caller() . '::snap_prefix'} = \&snap_prefix; | |||||||||||||
| 17 | 19 | *{caller() . '::snap_layout'} = \&snap_layout; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 32 | ▶ | sub snapshot { | ||||||||||||
|
Subroutine
snapshot: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 21 | 32 | my($self, $value) = @_; | |||||||||||||
| 22 | 32 | ▶ | $snapshot = $value if defined $value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 32 | $snapshot; | |||||||||||||
| 24 | } | ||||||||||||||
| 25 | |||||||||||||||
| 26 | 18 | ▶ | sub snap_layout { | ||||||||||||
|
Subroutine
snap_layout: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 27 | 18 | my($self, $value) = @_; | |||||||||||||
| 28 | 18 | ▶ | $snap_layout = $value if defined $value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | 18 | $snap_layout; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 18 | ▶ | sub snapshots_to { | ||||||||||||
|
Subroutine
snapshots_to: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 33 | 18 | my($self, $value) = @_; | |||||||||||||
| 34 | 18 | ▶ | $snapdir = $value if defined $value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 18 | $snapdir; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 18 | ▶ | sub snap_prefix { | ||||||||||||
|
Subroutine
snap_prefix: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 39 | 18 | my($self, $value) = @_; | |||||||||||||
| 40 | 18 | ▶ | $snap_prefix = $value if defined $value; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 41 | 18 | $snap_prefix; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 18 | ▶ | sub options { | ||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 45 | 18 | return ('snap_dir=s' => \$snapdir, | |||||||||||||
| 46 | 'snap_prefix=s' => \$snap_prefix, | ||||||||||||||
| 47 | 'snapshot=s' => \$snapshot, | ||||||||||||||
| 48 | 'snap_layout=s' => \$snap_layout, | ||||||||||||||
| 49 | ); | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 18 | ▶ | sub validate_options { | ||||||||||||
|
Subroutine
validate_options: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 53 | 18 | my($class, $app) = @_; | |||||||||||||
| 54 | 18 | ▶ | if (defined (my $dir = $app->snapshots_to)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | 10 | $app->pragma('snap_dir')->($app, $dir); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 18 | ▶ | if (defined (my $prefix = $app->snap_prefix)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 4 | $app->pragma('snap_prefix')->($app, $prefix); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | 18 | ▶ | if (defined (my $layout = $app->snap_layout)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 1 | $app->pragma('snap_layout')->($app, $layout); | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | 18 | ▶ | sub pragmas { | ||||||||||||
|
Subroutine
pragmas: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 66 | 18 | return (['snap_dir' => \&snapshot_dir_pragma], | |||||||||||||
| 67 | ['snapshot' => \&snapshot_pragma], | ||||||||||||||
| 68 | ['snap_prefix' => \&snap_prefix_pragma], | ||||||||||||||
| 69 | ['snap_layout' => \&snap_layout_pragma], | ||||||||||||||
| 70 | ); | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 16 | ▶ | sub snapshot_dir_pragma { | ||||||||||||
|
Subroutine
snapshot_dir_pragma: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 74 | 16 | my ($self, $args) = @_; | |||||||||||||
| 75 | 16 | $self->stack_code(qq(mech->snapshots_to("$args");\n)); | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 12 | ▶ | sub snapshot_pragma { | ||||||||||||
|
Subroutine
snapshot_pragma: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||
| 79 | 12 | my($self, $args) = @_; | |||||||||||||
| 80 | 12 | ▶ | if ($args eq 'on') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 81 | 9 | $self->snapshot('on'); | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | elsif ($args =~ /^error(s?)/) { | ||||||||||||||
| 84 | 3 | $self->snapshot('error'); | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | else { | ||||||||||||||
| 87 | 0 | $self->stack_code(qq(diag "Invalid snapshot type '$args'; 'error' assumed";\n)); | |||||||||||||
| 88 | 0 | $self->snapshot('error'); | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | } | ||||||||||||||
| 91 | |||||||||||||||
| 92 | 6 | ▶ | sub snap_prefix_pragma { | ||||||||||||
|
Subroutine
snap_prefix_pragma: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 93 | 6 | my ($self, $args) = @_; | |||||||||||||
| 94 | 6 | $self->stack_code(qq(mech->snap_prefix("$args");\n)); | |||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 1 | ▶ | sub snap_layout_pragma { | ||||||||||||
|
Subroutine
snap_layout_pragma: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 98 | 1 | my ($self, $args) = @_; | |||||||||||||
| 99 | 1 | $self->stack_code(qq(mech->snap_layout("$args");\n)); | |||||||||||||
| 100 | } | ||||||||||||||
| 101 | |||||||||||||||
| 102 | 18 | ▶ | sub filters { | ||||||||||||
|
Subroutine
filters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 103 | 18 | return \&filter; | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | |||||||||||||||
| 106 | 20 | ▶ | sub filter { | ||||||||||||
|
Subroutine
filter: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||
| 107 | 20 | my($self, @code) = @_; | |||||||||||||
| 108 | 20 | my $snap_kind = $self->snapshot; | |||||||||||||
| 109 | 20 | ▶ | return @code unless defined $snap_kind; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 110 | |||||||||||||||
| 111 | 18 | my $snapshot_comment; | |||||||||||||
| 112 | 18 | my $testspec = $self->get_current_spec; | |||||||||||||
| 113 | |||||||||||||||
| 114 | 18 | ▶ | if (defined $testspec) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | 18 | my $comment = $testspec -> comment; | |||||||||||||
| 116 | 18 | my $url = $testspec -> uri; | |||||||||||||
| 117 | 18 | my $regex = $testspec -> regex; | |||||||||||||
| 118 | 18 | my $test_kind = $testspec -> kind; | |||||||||||||
| 119 | 18 | $snapshot_comment = qq($comment<br>$url<br>$regex $test_kind); | |||||||||||||
| 120 | } | ||||||||||||||
| 121 | else { | ||||||||||||||
| 122 | 0 | my $line = $self->last_line(); | |||||||||||||
| 123 | 0 | $snapshot_comment = qq(Generated code for $line); | |||||||||||||
| 124 | } | ||||||||||||||
| 125 | |||||||||||||||
| 126 | 18 | ▶ | if ($snap_kind eq 'on') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 127 | 12 | push @code, <<EOS; | |||||||||||||
| 128 | diag "See snapshot " . mech->snapshot( qq($snapshot_comment) ); | ||||||||||||||
| 129 | EOS | ||||||||||||||
| 130 | } | ||||||||||||||
| 131 | elsif ($snap_kind eq 'error') { | ||||||||||||||
| 132 | 6 | push @code, <<EOS; | |||||||||||||
| 133 | if (!last_test->{ok}) { | ||||||||||||||
| 134 | diag "See snapshot " . mech->snapshot( qq($snapshot_comment) ); | ||||||||||||||
| 135 | } | ||||||||||||||
| 136 | EOS | ||||||||||||||
| 137 | } | ||||||||||||||
| 138 | 18 | return @code; | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 20 | 1; # Magic true value required at end of module | |||||||||||||
| 142 | __END__ | ||||||||||||||