| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package DBIx::Class::Helper::ResultSet::BooleanMethods; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 130033 | use 5.008; | 
|  | 1 |  |  |  |  | 3 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use utf8; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 5 | 1 |  |  | 1 |  | 426 | use strictures 2; | 
|  | 1 |  |  |  |  | 1295 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.05'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | =head1 NAME | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | DBIx::Class::Helper::ResultSet::BooleanMethods - Automatically create search methods for boolean columns. | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 VERSION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | Version 0.05 | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 1 |  |  | 1 |  | 632 | use Package::Variant 'importing' => ['Moo::Role']; | 
|  | 1 |  |  |  |  | 4636 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub make_variant { | 
| 22 | 0 |  |  | 0 | 0 |  | my ($class, $target_package, $resultset) = @_; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 0 |  |  |  |  |  | my $result = $resultset; | 
| 25 | 0 |  |  |  |  |  | $result =~ s/::ResultSet::/::Result::/oms; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 |  |  |  |  |  | my $columns_info = $result->result_source_instance->columns_info; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 0 |  |  |  |  |  | $resultset->load_components('Helper::ResultSet::Me'); | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 0 |  |  |  |  |  | for my $method (keys %{$columns_info}) { | 
|  | 0 |  |  |  |  |  |  | 
| 32 | 0 |  |  |  |  |  | my $detail = $columns_info->{$method}; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 0 | 0 |  |  |  |  | if ('boolean' ne $detail->{'data_type'}) { | 
| 35 | 0 |  |  |  |  |  | next; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | install "${method}" => sub { | 
| 39 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 0 |  |  |  |  |  | return $self->search( | 
| 42 |  |  |  |  |  |  | { | 
| 43 |  |  |  |  |  |  | $self->me($method) => 'true' | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  | ); | 
| 46 | 0 |  |  |  |  |  | }; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | install "not_${method}" => sub { | 
| 49 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | return $self->search( | 
| 52 |  |  |  |  |  |  | { | 
| 53 |  |  |  |  |  |  | $self->me($method) => 'false' | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | ); | 
| 56 | 0 |  |  |  |  |  | }; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 0 |  |  |  |  |  | return; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | This module automatically creates search method helpers for boolean columns. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | In your ResultSet class, add: | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | use Role::Tiny::With qw(with); | 
| 69 |  |  |  |  |  |  | use DBIx::Class::Helper::ResultSet::BooleanMethods; | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | with(BooleanMethods(__PACKAGE__)); | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =head1 METHODS | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | Say your table has a boolean column named "paid", using this role will act as if you added these methods: | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | sub paid { | 
| 78 |  |  |  |  |  |  | my $self = shift; | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | return $self->search( | 
| 81 |  |  |  |  |  |  | { | 
| 82 |  |  |  |  |  |  | 'paid' => 'true', | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | ); | 
| 85 |  |  |  |  |  |  | }; | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub not_paid { | 
| 88 |  |  |  |  |  |  | my $self = shift; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | return $self->search( | 
| 91 |  |  |  |  |  |  | { | 
| 92 |  |  |  |  |  |  | 'paid' => 'false', | 
| 93 |  |  |  |  |  |  | } | 
| 94 |  |  |  |  |  |  | ); | 
| 95 |  |  |  |  |  |  | }; | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =head1 AUTHOR | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | Mathieu Arnold, C<< <mat at cpan.org> >> | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head1 BUGS | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | Please report any bugs or feature requests to C<bug-dbix-class-helper-resultset-booleanmethods at rt.cpan.org>, or through | 
| 104 |  |  |  |  |  |  | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Helper-ResultSet-BooleanMethods>.  I will be notified, and then you'll | 
| 105 |  |  |  |  |  |  | automatically be notified of progress on your bug as I make changes. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | =head1 SUPPORT | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | perldoc DBIx::Class::Helper::ResultSet::BooleanMethods | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | You can also look for information at: | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =over 4 | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =item * RT: CPAN's request tracker (report bugs here) | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-Helper-ResultSet-BooleanMethods> | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | L<https://cpanratings.perl.org/d/DBIx-Class-Helper-ResultSet-BooleanMethods> | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =item * Search CPAN | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | L<https://metacpan.org/release/DBIx-Class-Helper-ResultSet-BooleanMethods> | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =back | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Thanks to the people of #dbix-class, they were very helpful in pointing me to the right direction. | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | This software is Copyright (c) 2019 by Mathieu Arnold. | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | This is free software, licensed under: | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | The Artistic License 2.0 (GPL Compatible) | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =cut | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | 1; |