App-FilenameKeyValueUtils

 view release on metacpan or  search on metacpan

script/parse-keyvalue-filename  view on Meta::CPAN

must match this regex:

 /\A
  (?:
   (.+?)                                 # optional prefix (part before the first key)
   -
  )?
  (
  (?:
    ([A-Za-z_][A-Za_z0-9_]*)              # key
    =
    ([^-]*)                               # value
  )
  (?:
    -
    ([A-Za-z_][A-Za_z0-9_]*)
    =
    ([^-]*)
  )*
  (\.\w+)?                                # optional filename extension
  \z/x

KeyValue naming scheme is used in the AssetView media assets organization scheme
(see L<Media::AssetView>).

This routine parses a filename and return a structure containing parsed
elements.

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--array-value>=I<s>

Always/never/maybe return value as array.

Default value:

 1

Valid values:

 [0,1,2]

The default (1) is to return a scalar when there is a single value, or an array
if there are multiple values, for example:

 foo-kw1=val1-kw2=val2,val2b-kw3=val3-kw1=val1b.jpg

then:

 kw1 = ['val1', 'val1b']
 kw2 = ['val2', 'val2b']
 kw3 = 'val3'

The setting 0 means to never return array, so will return a comma-separated
string instead. However, if the value is URI-decoded then this can potentially
be ambiguous:

 kw1=val1,val2-kw1=val3%2cval4.jpg

under array_value=0 and decode_value=1 will return:

 kw1 = 'val1,val2,val3,val4'

while under array_value=1 or 2 will return 3 elements:

 kw1 = ['val1', 'val2', 'val3,val4']


=item B<--filename>=I<s>*

(No description)


Can also be specified as the 1st command-line argument.

=item B<--no-decode-value>

(No description)


=back

=head2 Output options

=over

=item B<--format>=I<s>

Choose output format, e.g. json, text.

Default value:

 undef

Output can be displayed in multiple formats, and a suitable default format is
chosen depending on the application and/or whether output destination is
interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.


=item B<--json>

Set output format to json.

=item B<--naked-res>

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

 [200,"OK",[1,2,3],{"func.extra"=>4}]



( run in 2.205 seconds using v1.01-cache-2.11-cpan-600a1bdf6e4 )