blib/lib/Pinto/Action/Diff.pm

filter: Statementstmt 90.2% 46 / 51 Branchbran 37.5% 3 / 8 Conditioncond 50.0% 6 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 1 totaltotal 74.1% 66 / 89 CC 10 SCAR 21.4
CC
10
Cov
77%
execute
17.3
_build_format
2.1
BEGIN
1.0
CRAP 8.5
« blib/lib/Pinto/Action/Reset.pm ↑ Summary blib/lib/Pinto/Schema/Result/Registration.pm »
1 # ABSTRACT: Show the difference between stacks or revisions
2  
3 package Pinto::Action::Diff;
4  
5 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use MooseX::Types::Moose qw(Bool Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Pinto::Difference;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Pinto::Constants qw(:color :diff);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Pinto::Types qw(StackName StackDefault StackObject RevisionID DiffStyle);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Pinto::Util qw(throw default_diff_style);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #------------------------------------------------------------------------------
17  
18 2 our $VERSION = '0.14'; # VERSION
19  
20 #------------------------------------------------------------------------------
21  
22 2 extends qw( Pinto::Action );
23  
24 #------------------------------------------------------------------------------
25  
26 2 has left => (
27 is => 'ro',
28 isa => StackName | StackObject | StackDefault | RevisionID,
29 default => undef,
30 );
31  
32 2 has right => (
33 is => 'ro',
34 isa => StackName | StackObject | RevisionID,
35 required => 1,
36 );
37  
38 2 has style => (
39 is => 'ro',
40 isa => DiffStyle,
41 alias => 'diff_style',
42 default => \&default_diff_style,
43 lazy => 1,
44 );
45  
46 2 has format => (
47 is => 'ro',
48 isa => Str,
49 builder => '_build_format',
50 );
51  
52 6 ▶sub _build_format {
Subroutine _build_format: called CC=2 SCAR=7.2
53 6 my ($self) = @_;
54  
55 6 ▶ return $self->style eq $PINTO_DIFF_STYLE_DETAILED
Branch: 1 branch
BranchTrueFalseTotal
$self->style eq $Pinto::Action::Diff::PINTO_DIFF_STYLE_DETAILED ? : 0 6 6
56 ? '%o[%F] %-40p %12v %a/%f'
57 : '%o[%F] %a/%f';
58 }
59  
60 #------------------------------------------------------------------------------
61  
62 7 ▶sub execute {
Subroutine execute: called CC=9 SCAR=28.5
Pod undocumented
63 7 my ($self) = @_;
64  
65 7 my $error_message = qq{"%s" does not match any stack or revision};
66  
67 7 ▶ my $left =
Condition50%3/6
$self->repo->get_stack_maybe($self->left) || $self->repo->get_revision_maybe($self->left) || throw(sprintf($error_message, $self->left))
l!l&&r!l&&!r
600
$self->repo->get_stack_maybe($self->left) or $self->repo->get_revision_maybe($self->left)
l!l&&r!l&&!r
330
MC/DC0%0/3
$self->repo->get_stack_maybe($self->left) || $self->repo->get_revision_maybe($self->left) || throw(sprintf($error_message, $self->left))
$self->repo->get_stack_maybe($self->left) $self->repo->get_revision_maybe($self->left) throw(sprintf($error_message, $self->left))
Truth table25%1/4
A or B || C
A= $self->repo->get_stack_maybe($self->left)B= $self->repo->get_revision_maybe($self->left)C= throw(sprintf($error_message, $self->left))
ABCresult
1XX1
01X1
0011
0000
68 $self->repo->get_stack_maybe( $self->left )
69 || $self->repo->get_revision_maybe( $self->left )
70 || throw sprintf $error_message, $self->left;
71  
72 6 ▶ my $right =
Condition50%3/6
$self->repo->get_stack_maybe($self->right) || $self->repo->get_revision_maybe($self->right) || throw(sprintf($error_message, $self->right))
l!l&&r!l&&!r
510
$self->repo->get_stack_maybe($self->right) or $self->repo->get_revision_maybe($self->right)
l!l&&r!l&&!r
006
MC/DC0%0/3
$self->repo->get_stack_maybe($self->right) || $self->repo->get_revision_maybe($self->right) || throw(sprintf($error_message, $self->right))
$self->repo->get_stack_maybe($self->right) $self->repo->get_revision_maybe($self->right) throw(sprintf($error_message, $self->right))
Truth table0%0/4
A or B || C
A= $self->repo->get_stack_maybe($self->right)B= $self->repo->get_revision_maybe($self->right)C= throw(sprintf($error_message, $self->right))
ABCresult
1XX1
01X1
0011
0000
73 $self->repo->get_stack_maybe( $self->right )
74 || $self->repo->get_revision_maybe( $self->right )
75 || throw sprintf $error_message, $self->right;
76  
77 5 my $diff = Pinto::Difference->new( left => $left,
78 right => $right,
79 style => $self->style );
80  
81 # TODO: Extract the colorizing & formatting code into a separate
82 # class that can be reused. Maybe subclassed for HTML and text.
83  
84 5 ▶ if ( $diff->is_different ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($diff->is_different) 0 5 5
85 0 $self->show( "--- $left", { color => $PINTO_PALETTE_COLOR_1 } );
86 0 $self->show( "+++ $right", { color => $PINTO_PALETTE_COLOR_1 } );
87 }
88  
89 5 for my $entry ( $diff->entries ) {
90 0 ▶ my $color = $entry->is_addition ? $PINTO_PALETTE_COLOR_0 : $PINTO_PALETTE_COLOR_2;
Branch: 1 branch
BranchTrueFalseTotal
$entry->is_addition ? : 0 0 0
91 0 my $string = $entry->to_string( $self->format );
92 0 $self->show( $string, { color => $color } );
93 }
94  
95 5 ▶ $self->notice('No difference') if not $diff->is_different;
Branch: 1 branch
BranchTrueFalseTotal
unless $diff->is_different 5 0 5
96  
97 5 return $self->result;
98 }
99  
100 #-------------------------------------------------------------------------------
101  
102 2 __PACKAGE__->meta->make_immutable;
103  
104 #------------------------------------------------------------------------------
105  
106 2 1;
107  
108 __END__
« blib/lib/Pinto/Action/Reset.pm ↑ Summary blib/lib/Pinto/Schema/Result/Registration.pm »