App-SahUtils

 view release on metacpan or  search on metacpan

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

 arg2=val2

 

which is equivalent to setting C<< -plugins=-DumpArgs@before_validate_args@99,-Foo@after_validate_args,arg1,val1,arg2,val2 >>.

List of available configuration parameters:

 coerce_rules (see --coerce-rule)
 coerce_to (see --coerce-to)
 compiler (see --compiler)
 data_as_json (see --data-as-json)
 data_as_perl (see --data-as-perl)
 data_with_result (see --data-with-result)
 format (see --format)
 linenum (see --linenum)
 multiple_data_as_json (see --multiple-data-as-json)
 multiple_data_as_perl (see --multiple-data-as-perl)
 naked_res (see --naked-res)
 return_type (see --return-type)
 show_code (see --show-code)
 show_rules (see --show-rules)
 type (see --type)

=head1 ENVIRONMENT

=head2 COERCE_WITH_SAH_OPT

String. Specify additional command-line options.

=head1 FILES

=head2 /home/u1/.config/coerce-with-sah.conf

=head2 /home/u1/coerce-with-sah.conf

=head2 /etc/coerce-with-sah.conf

=head1 EXAMPLES

=head2 Example #1

 % coerce-with-sah date --coerce-to DateTime --data-as-perl '"2016-05-22"'
 do {
   my $a = bless({
     formatter       => undef,
     local_c         => {
                          day => 22,
                          day_of_quarter => 52,
                          day_of_week => 7,
                          day_of_year => 143,
                          hour => 0,
                          minute => 0,
                          month => 5,
                          quarter => 2,
                          second => 0,
                          year => 2016,
                        },
     local_rd_days   => 736106,
     local_rd_secs   => 0,
     locale          => bless({
                          am_pm_abbreviated               => ["AM", "PM"],
                          available_formats               => {
                                                               "Bh"                => "h B",
                                                               "Bhm"               => "h:mm B",
                                                               "Bhms"              => "h:mm:ss B",
                                                               "d"                 => "d",
                                                               "E"                 => "ccc",
                                                               "EBhm"              => "E h:mm B",
                                                               "EBhms"             => "E h:mm:ss B",
                                                               "Ed"                => "d E",
                                                               "EHm"               => "E HH:mm",
                                                               "Ehm"               => "E h:mm\x{202F}a",
                                                               "Ehm-alt-ascii"     => "E h:mm a",
                                                               "Ehms"              => "E h:mm:ss\x{202F}a",
                                                               "EHms"              => "E HH:mm:ss",
                                                               "Ehms-alt-ascii"    => "E h:mm:ss a",
                                                               "Gy"                => "y G",
                                                               "GyMd"              => "M/d/y G",
                                                               "GyMMM"             => "MMM y G",
                                                               "GyMMMd"            => "MMM d, y G",
                                                               "GyMMMEd"           => "E, MMM d, y G",
                                                               "H"                 => "HH",
                                                               "h"                 => "h\x{202F}a",
                                                               "h-alt-ascii"       => "h a",
                                                               "Hm"                => "HH:mm",
                                                               "hm"                => "h:mm\x{202F}a",
                                                               "hm-alt-ascii"      => "h:mm a",
                                                               "hms"               => "h:mm:ss\x{202F}a",
                                                               "Hms"               => "HH:mm:ss",
                                                               "hms-alt-ascii"     => "h:mm:ss a",
                                                               "Hmsv"              => "HH:mm:ss v",
                                                               "hmsv"              => "h:mm:ss\x{202F}a v",
                                                               "hmsv-alt-ascii"    => "h:mm:ss a v",
                                                               "Hmv"               => "HH:mm v",
                                                               "hmv"               => "h:mm\x{202F}a v",
                                                               "hmv-alt-ascii"     => "h:mm a v",
                                                               "M"                 => "L",
                                                               "Md"                => "M/d",
                                                               "MEd"               => "E, M/d",
                                                               "MMM"               => "LLL",
                                                               "MMMd"              => "MMM d",
                                                               "MMMEd"             => "E, MMM d",
                                                               "MMMMd"             => "MMMM d",
                                                               "MMMMW-count-one"   => "'week' W 'of' MMMM",
                                                               "MMMMW-count-other" => "'week' W 'of' MMMM",
                                                               "ms"                => "mm:ss",
                                                               "y"                 => "y",
                                                               "yM"                => "M/y",
                                                               "yMd"               => "M/d/y",
                                                               "yMEd"              => "E, M/d/y",
                                                               "yMMM"              => "MMM y",
                                                               "yMMMd"             => "MMM d, y",
                                                               "yMMMEd"            => "E, MMM d, y",
                                                               "yMMMM"             => "MMMM y",
                                                               "yQQQ"              => "QQQ y",
                                                               "yQQQQ"             => "QQQQ y",
                                                               "yw-count-one"      => "'week' w 'of' Y",
                                                               "yw-count-other"    => "'week' w 'of' Y",
                                                             },
                          code                            => "en-US",
                          date_format_full                => "EEEE, MMMM d, y",
                          date_format_long                => "MMMM d, y",
                          date_format_medium              => "MMM d, y",
                          date_format_short               => "M/d/yy",
                          datetime_format_full            => "{1}, {0}",
                          datetime_format_long            => "{1}, {0}",
                          datetime_format_medium          => "{1}, {0}",
                          datetime_format_short           => "{1}, {0}",
                          day_format_abbreviated          => ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
                          day_format_narrow               => ["M", "T", "W", "T", "F", "S", "S"],
                          day_format_wide                 => [
                                                               "Monday",
                                                               "Tuesday",
                                                               "Wednesday",
                                                               "Thursday",
                                                               "Friday",
                                                               "Saturday",
                                                               "Sunday",
                                                             ],
                          day_stand_alone_abbreviated     => ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
                          day_stand_alone_narrow          => ["M", "T", "W", "T", "F", "S", "S"],
                          day_stand_alone_wide            => [
                                                               "Monday",
                                                               "Tuesday",
                                                               "Wednesday",
                                                               "Thursday",
                                                               "Friday",
                                                               "Saturday",
                                                               "Sunday",
                                                             ],
                          default_date_format_length      => "medium",
                          default_time_format_length      => "medium",
                          era_abbreviated                 => ["BC", "AD"],
                          era_narrow                      => ["B", "A"],
                          era_wide                        => ["Before Christ", "Anno Domini"],
                          first_day_of_week               => 7,
                          glibc_date_1_format             => "%a %b %e %r %Z %Y",
                          glibc_date_format               => "%m/%d/%Y",
                          glibc_datetime_format           => "%a %d %b %Y %r %Z",
                          glibc_time_12_format            => "%I:%M:%S %p",
                          glibc_time_format               => "%r",
                          language                        => "English",
                          locale_data                     => {
                                                               am_pm_abbreviated               => 'fix',
                                                               available_formats               => 'fix',
                                                               code                            => "en-US",
                                                               date_format_full                => "EEEE, MMMM d, y",
                                                               date_format_long                => "MMMM d, y",
                                                               date_format_medium              => "MMM d, y",
                                                               date_format_short               => "M/d/yy",
                                                               datetime_format_full            => "{1}, {0}",
                                                               datetime_format_long            => "{1}, {0}",
                                                               datetime_format_medium          => "{1}, {0}",
                                                               datetime_format_short           => "{1}, {0}",
                                                               day_format_abbreviated          => 'fix',
                                                               day_format_narrow               => 'fix',
                                                               day_format_wide                 => 'fix',
                                                               day_stand_alone_abbreviated     => 'fix',
                                                               day_stand_alone_narrow          => 'fix',
                                                               day_stand_alone_wide            => 'fix',
                                                               era_abbreviated                 => 'fix',
                                                               era_narrow                      => 'fix',
                                                               era_wide                        => 'fix',
                                                               first_day_of_week               => 7,
                                                               glibc_date_1_format             => "%a %b %e %r %Z %Y",
                                                               glibc_date_format               => "%m/%d/%Y",
                                                               glibc_datetime_format           => "%a %d %b %Y %r %Z",
                                                               glibc_time_12_format            => "%I:%M:%S %p",
                                                               glibc_time_format               => "%r",
                                                               language                        => "English",
                                                               month_format_abbreviated        => [
                                                                                                    "Jan",
                                                                                                    "Feb",
                                                                                                    "Mar",
                                                                                                    "Apr",
                                                                                                    "May",
                                                                                                    "Jun",
                                                                                                    "Jul",
                                                                                                    "Aug",
                                                                                                    "Sep",
                                                                                                    "Oct",
                                                                                                    "Nov",
                                                                                                    "Dec",
                                                                                                  ],
                                                               month_format_narrow             => ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
                                                               month_format_wide               => [
                                                                                                    "January",
                                                                                                    "February",
                                                                                                    "March",
                                                                                                    "April",
                                                                                                    "May",
                                                                                                    "June",
                                                                                                    "July",
                                                                                                    "August",
                                                                                                    "September",
                                                                                                    "October",
                                                                                                    "November",
                                                                                                    "December",
                                                                                                  ],
                                                               month_stand_alone_abbreviated   => [
                                                                                                    "Jan",
                                                                                                    "Feb",
                                                                                                    "Mar",

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

                              60683964000,
                              60962776800,
                              60683990400,
                              60962803200,
                              26400,
                              0,
                              "+0720",
                            ],
                            [
                              60962776800,
                              61259041800,
                              60962803800,
                              61259068800,
                              27000,
                              0,
                              "+0730",
                            ],
                            [
                              61259041800,
                              61369628400,
                              61259074200,
                              61369660800,
                              32400,
                              0,
                              "+09",
                            ],
                            [
                              61369628400,
                              61451800200,
                              61369655400,
                              61451827200,
                              27000,
                              0,
                              "+0730",
                            ],
                            [
                              61451800200,
                              61514870400,
                              61451829000,
                              61514899200,
                              28800,
                              0,
                              "+08",
                            ],
                            [
                              61514870400,
                              61946267400,
                              61514897400,
                              61946294400,
                              27000,
                              0,
                              "+0730",
                            ],
                            [61946267400, "Inf", 61946292600, "Inf", 25200, 0, "WIB"],
                          ],
                        }, "DateTime::TimeZone::Asia::Jakarta"),
     utc_rd_days     => 736105,
     utc_rd_secs     => 61200,
     utc_year        => 2017,
   }, "DateTime");
   $a->{locale}{locale_data}{am_pm_abbreviated} = $a->{locale}{am_pm_abbreviated};
   $a->{locale}{locale_data}{available_formats} = $a->{locale}{available_formats};
   $a->{locale}{locale_data}{day_format_abbreviated} = $a->{locale}{day_format_abbreviated};
   $a->{locale}{locale_data}{day_format_narrow} = $a->{locale}{day_format_narrow};
   $a->{locale}{locale_data}{day_format_wide} = $a->{locale}{day_format_wide};
   $a->{locale}{locale_data}{day_stand_alone_abbreviated} = $a->{locale}{day_stand_alone_abbreviated};
   $a->{locale}{locale_data}{day_stand_alone_narrow} = $a->{locale}{day_stand_alone_narrow};
   $a->{locale}{locale_data}{day_stand_alone_wide} = $a->{locale}{day_stand_alone_wide};
   $a->{locale}{locale_data}{era_abbreviated} = $a->{locale}{era_abbreviated};
   $a->{locale}{locale_data}{era_narrow} = $a->{locale}{era_narrow};
   $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



( run in 2.257 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )