| 1 | package WebService::PivotalTracker::PropertyAttributes; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.12'; | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use Scalar::Util qw( blessed ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Sub::Quote qw( quote_sub ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Exporter qw( import ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | ## no critic (Modules::ProhibitAutomaticExportation) | ||||||||||
| 14 | 1 | our @EXPORT = 'props_to_attributes'; | |||||||||
| 15 | |||||||||||
| 16 | 8 | ▶ | sub props_to_attributes { | ||||||||
|
Subroutine
props_to_attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 8 | my %props = @_; | |||||||||
| 18 | |||||||||||
| 19 | 8 | my $caller = caller(); | |||||||||
| 20 | 8 | return map { [ $_ => _attr_for( $caller, $_, $props{$_} ) ] } keys %props; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 99 | ▶ | sub _attr_for { | ||||||||
|
Subroutine
_attr_for: called CC=5 SCAR=16.1
| |||||||||||
| 24 | 99 | my $caller = shift; | |||||||||
| 25 | 99 | my $name = shift; | |||||||||
| 26 | 99 | my $prop = shift; | |||||||||
| 27 | |||||||||||
| 28 | 99 | ▶ | $prop = { type => $prop } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | if blessed $prop; | ||||||||||
| 30 | |||||||||||
| 31 | 99 | my $default = q{}; | |||||||||
| 32 | 99 | my %env; | |||||||||
| 33 | 99 | ▶ | if ( $prop->{may_require_refresh} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | $default .= sprintf( <<'EOF', $name ); | |||||||||
| 35 | $_[0]->_refresh_raw_content unless exists $_[0]->raw_content->{%s}; | ||||||||||
| 36 | EOF | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 99 | ▶ | if ( $prop->{default} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 2 | $env{'$default'} = \$prop->{default}; | |||||||||
| 41 | 2 | $default .= sprintf( <<'EOF', $name, $name ); | |||||||||
| 42 | my $val = exists $_[0]->raw_content->{%s} ? $_[0]->raw_content->{%s} : $default->(); | ||||||||||
| 43 | EOF | ||||||||||
| 44 | } | ||||||||||
| 45 | else { | ||||||||||
| 46 | 97 | $default .= sprintf( <<'EOF', $name ); | |||||||||
| 47 | my $val = $_[0]->raw_content->{%s}; | ||||||||||
| 48 | EOF | ||||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 99 | ▶ | if ( $prop->{inflator} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 21 | $default .= sprintf( <<'EOF', $prop->{inflator} ); | |||||||||
| 53 | return unless defined $val; | ||||||||||
| 54 | return $_[0]->%s( $val ); | ||||||||||
| 55 | EOF | ||||||||||
| 56 | } | ||||||||||
| 57 | else { | ||||||||||
| 58 | 78 | $default .= 'return $val;'; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 99 | my $subname = join '::', $caller, '_build_' . $name; | |||||||||
| 62 | return ( | ||||||||||
| 63 | is => 'ro', | ||||||||||
| 64 | isa => $prop->{type}, | ||||||||||
| 65 | 99 | init_arg => undef, | |||||||||
| 66 | lazy => 1, | ||||||||||
| 67 | default => quote_sub( $subname, $default, \%env ), | ||||||||||
| 68 | clearer => '_clear_' . $name, | ||||||||||
| 69 | ); | ||||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 1 | 1; | |||||||||
| 73 | |||||||||||
| 74 | # ABSTRACT: An internal tool; nothing to see here, move along | ||||||||||
| 75 | |||||||||||
| 76 | =pod | ||||||||||
| 77 | |||||||||||
| 78 | =encoding UTF-8 | ||||||||||
| 79 | |||||||||||
| 80 | =head1 NAME | ||||||||||
| 81 | |||||||||||
| 82 | WebService::PivotalTracker::PropertyAttributes - An internal tool; nothing to see here, move along | ||||||||||
| 83 | |||||||||||
| 84 | =head1 VERSION | ||||||||||
| 85 | |||||||||||
| 86 | version 0.12 | ||||||||||
| 87 | |||||||||||
| 88 | =head1 DESCRIPTION | ||||||||||
| 89 | |||||||||||
| 90 | This package has no user-facing parts. | ||||||||||
| 91 | |||||||||||
| 92 | =for Pod::Coverage *EVERYTHING* | ||||||||||
| 93 | |||||||||||
| 94 | =head1 SUPPORT | ||||||||||
| 95 | |||||||||||
| 96 | Bugs may be submitted through L<https://github.com/maxmind/WebService-PivotalTracker/issues>. | ||||||||||
| 97 | |||||||||||
| 98 | =head1 AUTHOR | ||||||||||
| 99 | |||||||||||
| 100 | Dave Rolsky <autarch@urth.org> | ||||||||||
| 101 | |||||||||||
| 102 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 103 | |||||||||||
| 104 | This software is Copyright (c) 2016 - 2020 by MaxMind, Inc. | ||||||||||
| 105 | |||||||||||
| 106 | This is free software, licensed under: | ||||||||||
| 107 | |||||||||||
| 108 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||