File Coverage

blib/lib/Pinto/Schema/Result/Registration.pm
Criterion Covered Total %
statement 58 81 71.6
branch 6 20 30.0
condition 4 16 25.0
subroutine 26 37 70.2
pod 1 9 11.1
total 95 163 58.2


line stmt bran cond sub pod time code
1 54     54   55134 use utf8;
  54         426  
  54         480  
2              
3             package Pinto::Schema::Result::Registration;
4              
5             # Created by DBIx::Class::Schema::Loader
6             # DO NOT MODIFY THE FIRST PART OF THIS FILE
7              
8              
9 54     54   2397 use strict;
  54         112  
  54         1253  
10 54     54   279 use warnings;
  54         123  
  54         1651  
11              
12 54     54   274 use Moose;
  54         127  
  54         430  
13 54     54   350052 use MooseX::NonMoose;
  54         1181  
  54         493  
14 54     54   364555 use MooseX::MarkAsMethods autoclean => 1;
  54         299  
  54         539  
15             extends 'DBIx::Class::Core';
16              
17              
18             __PACKAGE__->table("registration");
19              
20              
21             __PACKAGE__->add_columns(
22             "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
23             "revision", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
24             "package_name", { data_type => "text", is_nullable => 0 },
25             "package", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
26             "distribution", { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
27             "is_pinned", { data_type => "boolean", is_nullable => 0 },
28             );
29              
30              
31             __PACKAGE__->set_primary_key("id");
32              
33              
34             __PACKAGE__->add_unique_constraint( "revision_package_name_unique", [ "revision", "package_name" ] );
35              
36              
37             __PACKAGE__->belongs_to(
38             "distribution",
39             "Pinto::Schema::Result::Distribution",
40             { id => "distribution" },
41             { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
42             );
43              
44              
45             __PACKAGE__->belongs_to(
46             "package",
47             "Pinto::Schema::Result::Package",
48             { id => "package" },
49             { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
50             );
51              
52              
53             __PACKAGE__->belongs_to(
54             "revision",
55             "Pinto::Schema::Result::Revision",
56             { id => "revision" },
57             { is_deferrable => 0, on_delete => "CASCADE", on_update => "NO ACTION" },
58             );
59              
60              
61             with 'Pinto::Role::Schema::Result';
62              
63             # Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-03-04 12:39:54
64             # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:AkBHZ7hQ0BdZdv0DoCJufA
65              
66             #------------------------------------------------------------------------------
67              
68             # ABSTRACT: Represents the relationship between a Package and a Stack
69              
70             #------------------------------------------------------------------------------
71              
72             our $VERSION = '0.14'; # VERSION
73              
74             #------------------------------------------------------------------------------
75              
76 54     54   341240 use String::Format;
  54         4841  
  54         4551  
77              
78 54     54   400 use Pinto::Util qw(itis throw);
  54         138  
  54         3738  
79              
80             use overload (
81 54         551 '""' => 'to_string',
82             'cmp' => 'string_compare',
83             '<=>' => 'numeric_compare',
84             fallback => undef
85 54     54   389 );
  54         410  
86              
87             #-------------------------------------------------------------------------------
88              
89             sub FOREIGNBUILDARGS {
90 199     199 0 708 my ( $class, $args ) = @_;
91              
92             # Should we default these here or in the database?
93              
94 199   50     674 $args ||= {};
95 199   50     1361 $args->{is_pinned} ||= 0;
96              
97 199         1265 return $args;
98             }
99              
100             #-------------------------------------------------------------------------------
101              
102 0     0 1 0 sub update { throw 'PANIC: Update to registrations are not allowed' }
103              
104             #-------------------------------------------------------------------------------
105              
106             sub pin {
107 4     4 0 81 my ($self) = @_;
108              
109 4 50       139 throw "$self is already pinned" if $self->is_pinned;
110              
111 4         91 $self->delete;
112 4         4119 my $copy = $self->copy( { is_pinned => 1 } );
113              
114 4         6834 return $copy;
115             }
116              
117             #-------------------------------------------------------------------------------
118              
119             sub unpin {
120 0     0 0 0 my ($self) = @_;
121              
122 0 0       0 throw "$self is not pinned" if not $self->is_pinned;
123              
124 0         0 $self->delete;
125 0         0 my $copy = $self->copy( { is_pinned => 0 } );
126              
127 0         0 return $copy;
128             }
129              
130             #-------------------------------------------------------------------------------
131              
132             sub numeric_compare {
133 0     0 0 0 my ( $reg_a, $reg_b ) = @_;
134              
135 0         0 my $pkg = __PACKAGE__;
136 0 0 0     0 throw "Can only compare $pkg objects"
137             if not( itis( $reg_a, $pkg ) && itis( $reg_b, $pkg ) );
138              
139 0 0       0 return 0 if $reg_a->id == $reg_b->id;
140              
141 0         0 return $reg_a->package <=> $reg_b->package;
142             }
143              
144             #------------------------------------------------------------------------------
145              
146             sub string_compare {
147 0     0 0 0 my ( $reg_a, $reg_b ) = @_;
148              
149 0         0 my $class = __PACKAGE__;
150 0 0 0     0 throw "Can only compare $class objects"
151             if not( itis( $reg_a, $class ) && itis( $reg_b, $class ) );
152              
153 0 0       0 return 0 if $reg_a->id == $reg_b->id;
154              
155             return
156 0   0     0 ( $reg_a->package->distribution->author cmp $reg_b->package->distribution->author )
157             || ( $reg_a->package->distribution->vname cmp $reg_b->package->distribution->vname )
158             || ( $reg_a->package->vname cmp $reg_b->package->vname );
159             }
160              
161             #------------------------------------------------------------------------------
162              
163             sub flags {
164 28     28 0 65 my ($self) = @_;
165              
166 28         62 my $format = '%m%s%y';
167 28         76 return $self->to_string($format);
168             }
169              
170             #------------------------------------------------------------------------------
171              
172             sub to_string {
173 356     356 0 2624920 my ( $self, $format ) = @_;
174              
175             # my ($pkg, $file, $line) = caller;
176             # warn __PACKAGE__ . " stringified from $file at line $line";
177              
178             my %fspec = (
179 5     5   401 p => sub { $self->package->name },
180 296     296   154571 P => sub { $self->package->vname },
181 5     5   416 v => sub { $self->package->version },
182 0 0   0   0 M => sub { $self->package->is_main_module ? 'm' : '-'},
183 324 100   324   25079 y => sub { $self->is_pinned ? '!' : '-' },
184 28 50   28   1482 m => sub { $self->distribution->is_devel ? 'd' : 'r' },
185 0     0   0 h => sub { $self->distribution->path },
186 0     0   0 H => sub { $self->distribution->native_path },
187 32     32   2986 f => sub { $self->distribution->archive },
188 30 100   30   1444 s => sub { $self->distribution->is_local ? 'l' : 'f' },
189 2     2   103 S => sub { $self->distribution->source },
190 328     328   25839 a => sub { $self->distribution->author },
191 0     0   0 d => sub { $self->distribution->name },
192 296     296   834484 D => sub { $self->distribution->vname },
193 0     0   0 V => sub { $self->distribution->version },
194 0     0   0 u => sub { $self->distribution->uri },
195 0     0   0 i => sub { $self->revision->uuid_prefix },
196 28     28   1391 F => sub { $self->flags },
197 356         12687 );
198              
199             # Some attributes are just undefined, usually because of
200             # oddly named distributions and other old stuff on CPAN.
201 54     54   49534 no warnings 'uninitialized'; ## no critic qw(NoWarnings);
  54         137  
  54         6843  
202              
203 356   66     2550 $format ||= $self->default_format();
204 356         2991 return String::Format::stringf( $format, %fspec );
205             }
206              
207             #-------------------------------------------------------------------------------
208              
209             sub default_format {
210              
211 288     288 0 1504 return '%a/%D/%P/%y'; # AUTHOR/DIST_VNAME/PKG_VNAME/PIN_STATUS
212             }
213              
214             #------------------------------------------------------------------------------
215              
216             __PACKAGE__->meta->make_immutable;
217              
218             #------------------------------------------------------------------------------
219             1;
220              
221             __END__
222              
223             =pod
224              
225             =encoding UTF-8
226              
227             =for :stopwords Jeffrey Ryan Thalhammer
228              
229             =head1 NAME
230              
231             Pinto::Schema::Result::Registration - Represents the relationship between a Package and a Stack
232              
233             =head1 VERSION
234              
235             version 0.14
236              
237             =head1 NAME
238              
239             Pinto::Schema::Result::Registration
240              
241             =head1 TABLE: C<registration>
242              
243             =head1 ACCESSORS
244              
245             =head2 id
246              
247             data_type: 'integer'
248             is_auto_increment: 1
249             is_nullable: 0
250              
251             =head2 revision
252              
253             data_type: 'integer'
254             is_foreign_key: 1
255             is_nullable: 0
256              
257             =head2 package_name
258              
259             data_type: 'text'
260             is_nullable: 0
261              
262             =head2 package
263              
264             data_type: 'integer'
265             is_foreign_key: 1
266             is_nullable: 0
267              
268             =head2 distribution
269              
270             data_type: 'integer'
271             is_foreign_key: 1
272             is_nullable: 0
273              
274             =head2 is_pinned
275              
276             data_type: 'boolean'
277             is_nullable: 0
278              
279             =head1 PRIMARY KEY
280              
281             =over 4
282              
283             =item * L</id>
284              
285             =back
286              
287             =head1 UNIQUE CONSTRAINTS
288              
289             =head2 C<revision_package_name_unique>
290              
291             =over 4
292              
293             =item * L</revision>
294              
295             =item * L</package_name>
296              
297             =back
298              
299             =head1 RELATIONS
300              
301             =head2 distribution
302              
303             Type: belongs_to
304              
305             Related object: L<Pinto::Schema::Result::Distribution>
306              
307             =head2 package
308              
309             Type: belongs_to
310              
311             Related object: L<Pinto::Schema::Result::Package>
312              
313             =head2 revision
314              
315             Type: belongs_to
316              
317             Related object: L<Pinto::Schema::Result::Revision>
318              
319             =head1 L<Moose> ROLES APPLIED
320              
321             =over 4
322              
323             =item * L<Pinto::Role::Schema::Result>
324              
325             =back
326              
327             =head1 AUTHOR
328              
329             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
330              
331             =head1 COPYRIGHT AND LICENSE
332              
333             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
334              
335             This is free software; you can redistribute it and/or modify it under
336             the same terms as the Perl 5 programming language system itself.
337              
338             =cut