Rit::Base::Utils - Utility functions for RitBase
Exportable.
TODO: Move most if not all of these functions to another place...
Please think about _not_ using these...
cache_clear() cache_clear( $time )
Sats the time of the cache clearing to $time that defaults to now().
Clears caches with nodes.
TODO: Broken. FIXME
Returns:
valclean( $value )
Exceptions: Will die if encountered a "Malformed UTF-8 character (fatal)"
Returns: The new value after a lot of transformation
$value = lc($value); $value =~ s/(aa)/Ã¥/g; $value =~ s/(æ|ae)/ä/g; $value =~ s/(ø|oe)/ö/g; $value =~ tr[à áâäãåéèêëÃìïîóòöôõúùüûýÿðþÃ] [aaaaaaeeeeiiiiooooouuuuyydps]; $value =~ tr/`'/'/; $value =~ tr/qwz/kvs/; $value =~ s/\b(och|and|o|o\.|og)\b/&/g; $value =~ s/\s\'n\b/&/g; $value =~ s/hote(ls|ller|lli|llin|llit|ll|l)/hotel/g; $value =~ s/[^\w&]//g;
name2url( $name )
Converts a name to a reasonable string to use in an url
Deprecated
Deprecated
parse_query_props( $string )
Splits the string to a list of values if separated by LF
.
The first part of each element should be a predicate and the rest, after the first space, should be the value.
Returns:
a props hash with pred/value pairs.
NB! Previously also split on ,
.
Example:
name Jonas Liljegren age 33 becomes: { name => 'Jonas Liljegren', age => '33', }
TODO: Handle things like: val (p1 val1, p2 val2 (ps1 vals1, ps2, vals2), p3 val3)
used by parse_query_props
parse_form_field_prop( $string )
Splits the string into an arg list.
The format is name1_val1__name2_val2__name3_val3...
Vals can be empty: name1___name2_val2...
Vals can contain underscore: pred_in_region...
The string can begin with check_
.
If a second property with the same name is encountered, it will return the values as an arrayref.
Returns:
a props hash with pred/value pairs.
Example:
arc___revpred_has_member__type_marketing_group__if_a__if_b becomes: { arc => undef, revpred => 'has_member', type => 'marketing_group', if => ['a','b'], }
parse_arc_add_box( $string, \%args )
Splits the string up with one property for each row.
The first part of each element should be a predicate and the rest, after the first space, should be the value.
Value nodes can be created by giving adding the value props after an
->
. Those props are parsed using /parse_query_props.
Returns:
a props hash with pred/value pairs.
Example:
name Sverige -> is_of_language sv (code) is country
This would create a node with the properties
$sverige = { is_of_language => 'sv (code)', }
And then return the hashref
{ name => $sverige, is => 'country', }
Note that the value node is created even if you don't use the returned hashref for creating the arcs using that value node.
The sv (code)
part will be parsed by
Rit::Base::Resource/find_by_anything, as will all the values.
parse_query_pred( $predstring, \%args )
Internal use...
parse_query_prop( \%props, \%args )
Internal use...
convert_query_prop_for_creation( \%props, \%args )
Accepts _clean
part.
Internal use...
is_undef()
Returns:
An Rit::Base::Undef object.
arc_lock()
Calls Rit::Base::Arc/lock
arc_unlock()
Calls Rit::Base::Arc/unlock
truncstring( $string, $length )
The string may be a string ref or an Rit::Base::Object. It doesnt
touch the string, but returns a string with a maximum of $length
chars. If shortened, ends with '...'.
Returns:
The shortened string.
string($string)
Calls Rit::Base::Literal::String/new with $string
.
html($string)
Calls Rit::Base::Literal::String/new with $string
and valtype
text_html
.
query_desig($query, \%args, $ident)
parse_propargs() parse_propargs( \%args ) parse_propargs( $special ) parse_propargs( $arclim )
\%args
holds any extra arguments to the method as name/value
pairs. The arclim
argument is always parsed and converted to a
Rit::Base::Arc::Lim object. This will modify the args variable in
cases when arclim isn't already a valid object.
$arclim
is given, in the right position, as anything other than a
hashref. It will be given to Rit::Base::Arc::Lim/parse, that takes
many alternative forms, including arrayrefs and scalar strings.
$arclim
may instead be given as a named parameter in \%args
.
The given $arclim
will be placed in a constructed $args
and
returned.
0
represents here a false argument, including undef or no
argument. This will generate an empty \%props
.
$special
can be a couple of standard configurations:
auto: If user has root access, sets arclim to ['not_old'] and unique_arcs_prio to ['new', 'submitted', 'active']. Otherwise, sets special to 'relative'.
relative: Sets arclim to ['active', ['not_old', 'created_by_me']] and unique_arcs_prio to ['new', 'submitted', 'active'].
solid: Sets arclim to ['active] and unique_arcs_prio to ['active'].
all: Sets arclim to [['active'], ['inactive']] and unique_arcs_prio to ['active'].
Arguments from Rit::Base::User/default_propargs are used for any UNEXISTING argument given. You can for example override the use of a default unique_arcs_prio by explicitly setting unique_arcs_prio to undef.
Returns in array context: ($arg
, $arclim
, $res
)
Returns in scalar context: $arg
The returned arclim
is also found as the arclim named parameter in
arg
, so that's just syntactic sugar. With no input, the return will
be the two values {}, []
, there []
is an empty
Rit::Base::Arc::Lim object (that can be generated by parsing
[]
).
proplim_to_arclim( \%proplim, $is_rev )
Converts a proplim for use in arclist by adding obj top criterions.
aais( \%args, $limit )
Stands for args_arclim_intersect
.
Returns: A new clone of args hashref, with a clone of the arclim modified with Rit::Base::Arc::Lim/add_intersect
alphanum_to_id( $alphanum )
my( $range, $range_pred ) = range_pred(\%args)