| 1 | package Plerd::Tag; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 13 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 13 | ▶ | use URI; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 13 | has 'plerd' => ( | |||||||||||||
| 7 | is => 'ro', | ||||||||||||||
| 8 | required => 1, | ||||||||||||||
| 9 | isa => 'Plerd', | ||||||||||||||
| 10 | weak_ref => 1, | ||||||||||||||
| 11 | ); | ||||||||||||||
| 12 | |||||||||||||||
| 13 | has 'posts' => ( | ||||||||||||||
| 14 | is => 'ro', | ||||||||||||||
| 15 | isa => 'ArrayRef[Plerd::Post]', | ||||||||||||||
| 16 | 2 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 13 | ); | |||||||||||||
| 18 | |||||||||||||||
| 19 | 13 | has 'name' => ( | |||||||||||||
| 20 | is => 'rw', | ||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||
| 22 | required => 1, | ||||||||||||||
| 23 | ); | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 13 | has 'uri' => ( | |||||||||||||
| 26 | is => 'ro', | ||||||||||||||
| 27 | isa => 'URI', | ||||||||||||||
| 28 | lazy_build => 1, | ||||||||||||||
| 29 | ); | ||||||||||||||
| 30 | |||||||||||||||
| 31 | 2 | ▶ | sub add_post { | ||||||||||||
|
Subroutine
add_post: called CC=6 SCAR=27.4
Pod
documented
| |||||||||||||||
| 32 | 2 | my ($self, $post) = @_; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | my $added = 0; | |||||||||||||
| 35 | 2 | ▶ | if ( @{$self->posts} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 0 | ▶ | for (my $index = 0; $index <= @{$self->posts} - 1; $index++ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 0 | ▶ | if ( $self->posts->[$index]->guid eq $post->guid ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 38 | 0 | return; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | elsif ( $self->posts->[$index]->date < $post->date ) { | ||||||||||||||
| 41 | 0 | splice @{$self->posts}, $index, 0, $post; | |||||||||||||
| 42 | 0 | $added = 1; | |||||||||||||
| 43 | 0 | last; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 2 | ▶ | unless ($added) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 2 | push @{$self->posts}, $post; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 6 | ▶ | sub ponder_new_name { | ||||||||||||
|
Subroutine
ponder_new_name: called CC=3 SCAR=15.0
Pod
documented
| |||||||||||||||
| 54 | 6 | my ($self, $new_name) = @_; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 6 | my $current_name = $self->name; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 6 | ▶ | if ( $current_name eq $new_name ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | 6 | return; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | else { | ||||||||||||||
| 62 | 0 | $self->plerd->add_tag_case_conflict( $new_name, $current_name ); | |||||||||||||
| 63 | 0 | ▶ | if ( not ($current_name =~ /[[:upper:]]/) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 0 | $self->name( $new_name ); | |||||||||||||
| 65 | |||||||||||||||
| 66 | } | ||||||||||||||
| 67 | } | ||||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 2 | ▶ | sub _build_uri { | ||||||||||||
|
Subroutine
_build_uri: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 2 | my $self = shift; | |||||||||||||
| 72 | |||||||||||||||
| 73 | 2 | return URI->new_abs( | |||||||||||||
| 74 | 'tags/' . $self->name . '.html', | ||||||||||||||
| 75 | $self->plerd->base_uri_with_slash, | ||||||||||||||
| 76 | ); | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 13 | 1; | |||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 NAME | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Plerd::Tag | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 DESCRIPTION | ||||||||||||||
| 86 | |||||||||||||||
| 87 | Objects of this class represent a categorization tag in a Plerd blog. | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head1 CLASS METHODS | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =over | ||||||||||||||
| 92 | |||||||||||||||
| 93 | =item new( \%config ) | ||||||||||||||
| 94 | |||||||||||||||
| 95 | Object constructor. The single config hashref I<must> include the | ||||||||||||||
| 96 | following keys: | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =over | ||||||||||||||
| 99 | |||||||||||||||
| 100 | =item plerd | ||||||||||||||
| 101 | |||||||||||||||
| 102 | The parent Plerd object. | ||||||||||||||
| 103 | |||||||||||||||
| 104 | =item name | ||||||||||||||
| 105 | |||||||||||||||
| 106 | This tag's name. Just an ordinary text string. | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =back | ||||||||||||||
| 109 | |||||||||||||||
| 110 | =back | ||||||||||||||
| 111 | |||||||||||||||
| 112 | =head1 ATTRIBUTES | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =over | ||||||||||||||
| 115 | |||||||||||||||
| 116 | =item posts | ||||||||||||||
| 117 | |||||||||||||||
| 118 | A list reference of all L<Plerd::Post> objects making use of this tag. | ||||||||||||||
| 119 | |||||||||||||||
| 120 | =item uri | ||||||||||||||
| 121 | |||||||||||||||
| 122 | A L<URI> object pointing to this tag's detail page. | ||||||||||||||
| 123 | |||||||||||||||
| 124 | =back | ||||||||||||||
| 125 | |||||||||||||||
| 126 | =head1 OBJECT METHODS | ||||||||||||||
| 127 | |||||||||||||||
| 128 | =over | ||||||||||||||
| 129 | |||||||||||||||
| 130 | =item add_post ( $post ) | ||||||||||||||
| 131 | |||||||||||||||
| 132 | Adds the given L<Plerd::Post> object to this tag's list of posts. | ||||||||||||||
| 133 | |||||||||||||||
| 134 | =item ponder_new_name ( $new_name ) | ||||||||||||||
| 135 | |||||||||||||||
| 136 | Given $new_name, this tag ponders whether it should replace its own name | ||||||||||||||
| 137 | with it. If it decides that that a replacement is due, it goes ahead and | ||||||||||||||
| 138 | performs the swap. | ||||||||||||||
| 139 | |||||||||||||||
| 140 | If the current name has no capital letters, and the new name does, then | ||||||||||||||
| 141 | the new name will indeed replace it. | ||||||||||||||
| 142 | |||||||||||||||
| 143 | For example, if a tag is named "foo", and we call this method with | ||||||||||||||
| 144 | "Foo", then this tag will rename itself to "Foo". If we call it again | ||||||||||||||
| 145 | with "foo", the tag will remain "Foo". | ||||||||||||||
| 146 | |||||||||||||||
| 147 | =back | ||||||||||||||
| 148 | |||||||||||||||
| 149 | =head1 SEE ALSO | ||||||||||||||
| 150 | |||||||||||||||
| 151 | L<Plerd> | ||||||||||||||
| 152 | |||||||||||||||
| 153 | =head1 AUTHOR | ||||||||||||||
| 154 | |||||||||||||||
| 155 | Jason McIntosh <jmac@jmac.org> | ||||||||||||||