From f2b33d6a43cde2f4e9c1170f3ae15a5cfb62d09e Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 10 Feb 2007 01:19:43 +0000 Subject: [PATCH] Separate tags with commas, split off tag parsing code to Tagtools to make it easier to test. Fixes #9. git-svn-id: http://svn.simon-cozens.org/memories/trunk@20 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 3 +-- Tagtools.pm | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index ce0cd20..bcfb59c 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -303,7 +303,6 @@ sub scale { } } -use Text::Balanced qw(extract_multiple extract_quotelike); sub edit_tags :Exported { my ($self, $r) = @_; my $photo = $r->objects->[0]; @@ -321,7 +320,7 @@ sub edit_tags :Exported { sub add_tags { my ($photo, $tagstring) = @_; - for my $tag (map { s/^"|"$//g; $_} extract_multiple(lc $tagstring, [ \&extract_quotelike, qr/([^\s]+)/ ], undef,1)) { + for my $tag (Tagtools->separate_tags($tagstring)) { $photo->add_to_tags({tag => Memories::Tag->find_or_create({name =>$tag}) }) } } diff --git a/Tagtools.pm b/Tagtools.pm index 0fc2529..292e6e5 100644 --- a/Tagtools.pm +++ b/Tagtools.pm @@ -4,6 +4,7 @@ use Carp; use Cache::FileCache; use Storable qw(freeze); use MIME::Base64; use Calendar::Simple; +use Text::Balanced qw(extract_multiple extract_quotelike); sub import { my $whence = caller; my ($class) = @_; @@ -57,6 +58,14 @@ sub import { } +sub separate_tags { + map { s/^"|"$//g; $_} + extract_multiple( + lc $_[1], [ + \&extract_quotelike, + qr/([^\s,]+)/ + ], undef,1) +} # THIS IS A HACK -- 2.39.5