App-SahUtils

 view release on metacpan or  search on metacpan

script/coerce-with-sah  view on Meta::CPAN

   $a->{locale}{locale_data}{era_wide} = $a->{locale}{era_wide};
   $a->{locale}{month_format_abbreviated} = $a->{locale}{locale_data}{month_format_abbreviated};
   $a->{locale}{month_format_narrow} = $a->{locale}{locale_data}{month_format_narrow};
   $a->{locale}{month_format_wide} = $a->{locale}{locale_data}{month_format_wide};
   $a->{locale}{month_stand_alone_abbreviated} = $a->{locale}{locale_data}{month_stand_alone_abbreviated};
   $a->{locale}{month_stand_alone_narrow} = $a->{locale}{locale_data}{month_stand_alone_narrow};
   $a->{locale}{month_stand_alone_wide} = $a->{locale}{locale_data}{month_stand_alone_wide};
   $a->{locale}{quarter_format_abbreviated} = $a->{locale}{locale_data}{quarter_format_abbreviated};
   $a->{locale}{quarter_format_narrow} = $a->{locale}{locale_data}{quarter_format_narrow};
   $a->{locale}{quarter_format_wide} = $a->{locale}{locale_data}{quarter_format_wide};
   $a->{locale}{quarter_stand_alone_abbreviated} = $a->{locale}{locale_data}{quarter_stand_alone_abbreviated};
   $a->{locale}{quarter_stand_alone_narrow} = $a->{locale}{locale_data}{quarter_stand_alone_narrow};
   $a->{locale}{quarter_stand_alone_wide} = $a->{locale}{locale_data}{quarter_stand_alone_wide};
   $a;
 }

=head2 Coerce multiple data

 % coerce-with-sah date --coerce-to 'float(epoch)' --multiple-data-as-perl '["2016-05-15", "1463328281"]'
 [1463245200, 1463328281]

=head2 Add one or more coerce rules

 % coerce-with-sah duration --coerce-rule From_str::human --coerce-rule From_str::iso8601 --data-as-perl '"P1Y2M"'
 36817200

=head2 Show source code

 % coerce-with-sah duration --coerce-to 'float(secs)' -c
 require Scalar::Util;
 require Time::Duration::Parse::AsHash;
 sub {
     my $data = shift;
     unless (defined $data) {
         return undef;
     }
     do { if ($data =~ /\A([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2})(\.[0-9]{1,9})?)?\z/) { my $res = do { if ($1 > 23) { ["Invalid hour '$1', must be between 0-23"] } elsif ($2 > 59) { ["Invalid minute '$2', must be between 0-59"] } elsif (defined $3...
 }

=head2 Show source code, with line number

 % coerce-with-sah duration --coerce-to 'DateTime::Duration' -c -l
    1|require DateTime::Duration;
    2|require Scalar::Util;
    3|require Time::Duration::Parse::AsHash;
    4|sub {
    5|    my $data = shift;
    6|    unless (defined $data) {
    7|        return undef;
    8|    }
    9|    do { if ($data =~ /\A([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2})(\.[0-9]{1,9})?)?\z/) { my $res = do { if ($1 > 23) { ["Invalid hour '$1', must be between 0-23"] } elsif ($2 > 59) { ["Invalid minute '$2', must be between 0-59"] } elsif (defin...
   10|}

=head2 Show source code (JavaScript)

 % coerce-with-sah date -C js -c
 function (data) {
     if (data === undefined || data === null) {
         return null;
     }
     return ((typeof(data)=='number' && data >= 100000000 && data <= 2147483648) ? ((new Date(data * 1000))) : (function() { if ((data instanceof Date)) { var _tmp1 = isNaN(data) ? ['Invalid date', data] : [null, data]; if (_tmp1[0]) { return null } ...
 }

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-SahUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-SahUtils>.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 CONTRIBUTING


To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.

Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
that are considered a bug and can be reported to me.

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2024, 2023, 2022, 2020, 2019, 2018, 2017, 2016, 2015 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-SahUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=cut



( run in 1.102 second using v1.01-cache-2.11-cpan-2398b32b56e )