File Coverage

blib/lib/Pinto/DifferenceEntry.pm
Criterion Covered Total %
statement 25 28 89.2
branch n/a
condition 1 3 33.3
subroutine 9 11 81.8
pod 0 5 0.0
total 35 47 74.4


line stmt bran cond sub pod time code
1             # ABSTRACT: Represents one addition or deletion in a diff
2              
3             package Pinto::DifferenceEntry;
4              
5 7     7   47 use Moose;
  7         15  
  7         46  
6 7     7   41914 use MooseX::StrictConstructor;
  7         18  
  7         63  
7 7     7   20792 use MooseX::MarkAsMethods ( autoclean => 1 );
  7         23  
  7         61  
8 7     7   22643 use MooseX::Types::Moose qw(Str);
  7         27  
  7         70  
9              
10 7     7   32054 use String::Format;
  7         1315  
  7         554  
11              
12             #------------------------------------------------------------------------------
13              
14             use overload (
15 7         88 q{""} => 'to_string',
16             'cmp' => 'string_compare',
17 7     7   47 );
  7         22  
18              
19             #------------------------------------------------------------------------------
20              
21             our $VERSION = '0.14'; # VERSION
22              
23             #------------------------------------------------------------------------------
24              
25             # TODO: Consider breaking this into separate Addition and Deletion subclasses,
26             # rather than using an "op" attribute to indicate which kind it is. That sort
27             # of "type" flag is always a code smell to me.
28              
29             #------------------------------------------------------------------------------
30              
31             has op => (
32             is => 'ro',
33             isa => Str,
34             required => 1
35             );
36              
37             has registration => (
38             is => 'ro',
39             isa => 'Pinto::Schema::Result::Registration',
40             required => 1,
41             );
42              
43             #------------------------------------------------------------------------------
44              
45 8     8 0 192 sub is_addition { shift->op eq '+' }
46              
47 0     0 0 0 sub is_deletion { shift->op eq '-' }
48              
49             #------------------------------------------------------------------------------
50              
51             sub to_string {
52 35     35 0 371 my ( $self, $format ) = @_;
53              
54 35         896 my %fspec = ( o => $self->op );
55              
56 35   33     110 $format ||= $self->default_format;
57 35         889 return $self->registration->to_string( String::Format::stringf($format, %fspec) );
58             }
59              
60             #------------------------------------------------------------------------------
61              
62             sub default_format {
63 0     0 0 0 my ($self) = @_;
64              
65 0         0 return '%o[%F] %-40p %12v %a/%f',
66             }
67              
68             #------------------------------------------------------------------------------
69              
70             sub string_compare {
71 18     18 0 3262 my ( $self, $other ) = @_;
72              
73 18         655 return $self->registration->distribution->name
74             cmp $other->registration->distribution->name;
75             }
76              
77             #------------------------------------------------------------------------------
78              
79             __PACKAGE__->meta->make_immutable;
80              
81             #------------------------------------------------------------------------------
82             1;
83              
84             __END__
85              
86             =pod
87              
88             =encoding UTF-8
89              
90             =for :stopwords Jeffrey Ryan Thalhammer
91              
92             =head1 NAME
93              
94             Pinto::DifferenceEntry - Represents one addition or deletion in a diff
95              
96             =head1 VERSION
97              
98             version 0.14
99              
100             =head1 AUTHOR
101              
102             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
103              
104             =head1 COPYRIGHT AND LICENSE
105              
106             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
107              
108             This is free software; you can redistribute it and/or modify it under
109             the same terms as the Perl 5 programming language system itself.
110              
111             =cut